This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I am pretty new at this so please bear with me.
I have a raspberrypi that I am trying to set up as a server to remotely monitor with. I cannot seem to get php embedded in html to work. My simple code is:
<!DOCTYPE html>
<head>
<title>A test</title>
</head>
<body>
<?php echo "hello world"; ?>
hello joe -----
</body>
</html>
When I access the server on the Pi from my laptop what I see in the browser is the 'hello joe-----' but not the 'hello world'. when I turn on the F12 debugger window it tells me html:1406 invalid tag start: ?> question marks do not start tags.
When I execute a similar file directly from the command line on the Pi in a terminal window [e.g. php5 test.php] it seems to run fine.
Could this be a php configuration issue?
thx
What official guide would that be?
In any event I solved the problem. I purged php5 from the Pi and reinstalled. That seems to have fixed it. Now it all works.
Related
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 3 years ago.
I just started to learn php. I am using lubuntu and that's why I don't want to install xampp, wamp, or similar programs because I have very limited resources.
I installed Apache server and php 7, which seems to be working fine because I can execute and visualize html code via localhost. The problem is when I run php code the web page shows blank. How can I fix this issue?
I have only one file on /var/www/html which is called index.php and can be visualize on localhost/index.php
php -v
php 7.2.19-0ubuntu0.18.10.1
apache2 -v
Server version: Apache/2.4.34 (Ubuntu)
The code I have on index.php is this:
<!DOCTYPE html>
<html>
<body>
something
<?php
echo "hello world";
?>
</body>
</html>
On localhost/index.php it only shows "something", which means apache server is running correctly and runs html code but I don't know why php doesn't run. If Instead I just run a file with php code like
<? php
phpinfo();
?>
it only shows a blank page.
If you see a blank page then normally something else is blowing up behind the scene. I suggest you check both Apache and PHP error logs. Normally you would find both in /var/log/*
It could very well be permission related or a module missing.
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
when i type my php code in a html file, using notepad++ as my text editor,why does it always show some of the code as text on the web page
eg.
<?php echo "hello world"; ?>
would output:
"hello world";?>
as text on the web page
why does it do this and how can I stop it?
You need to save your PHP code in a file with .php extension. To execute PHP code, you can call the interpreter from your command line with php myfile.php or from a webserver like Apache or nginx.
Your browser cannot execute PHP code.
Read more about installing PHP here:
http://php.net/manual/en/install.php
If you're new to PHP, I would recommend you to read a good book (unfortunately I can't recommend one). Or if you're more the visual learner, take a look at The PHP Practioner made by Jeffrey Way.
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
So I'm just starting to learn php, and when trying " Hello World" the file isn't executing properly. I have Bitnami MAMP Stack 5.6.31 .
I'm pretty sure it's not something wrong with the code, possibly with the install of the AMP stack, but this is the code anyway :
<?php echo "Hello World"; ?>
You can't just "open" PHP files on XAMPP/MAMP/LAMPP/etc.
Make sure your apache service is started in your MAMP console
Make sure your file is saved in the document root of MAMP, which by default is 'MAMP/htdocs'
If your file, say is stored like this: 'MAMP/htdocs/learningPHP/hello.php' then you would go to your web browser and type in localhost/learningPHP/hello.php
The script will then run.
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
Simple, I had a html that echo from php (saven in .php) but not even a simpe code as
<?php echo"ggg"; ?>
works, I tried with xammp and Wamp either chrome and firefox but doesn't work.
What can I do?
edit: already solved, I forgot to run it from localhost, thank you all.
Any of these (or more) could be your answer why it is not working
Is there actually PHP running on your computer? Check it with <?php echo phpinfo(); ?>
Are you accesing the file through your browser doing something like http://localhost/myfile.php
If it is on a remote server, is there PHP installed?
https://stackoverflow.com/a/43129028/2151290
Put your file inside c:/xampp/htdocs for xampp or c:/wamp/www for wamp
// Note that drive name may vary depending where you install c: or d:
I recently installed an Apache2 web server, and PHP5 on my Raspberry Pi, and hooked it to my home router. It all works fine in terms of displaying HTML, even when the index document is a .php file. However, as soon as I try to enter any PHP code, and run it through my browser, it's completely removed from the document.
<html>
<head>
<?php
$baseUser = fopen("GCusernames.txt", "a");
$newUser = $_POST['user'];
fwrite($baseUser, $newUser);
fclose($baseUser);
?>
</head>
<body>
<h1>Writing to userbase</h1>
</body>
</html>
PHP document inspected in my browser
I've tried changing it back and forth to a HTML file and scouring the internet for clues. But everything I found was seriously unclear and vague.
I'd appreciate any help at all. Thanks.
UPDATE: So after I realized how idiotic I was (thank you everyone who answered,) I now understand that the PHP code shouldn't show up in the browser anyway. Sorry about that.
However, it still doesn't explain why the code doesn't execute at all. It just goes straight to the PHP page, rather than executing it.
PHP is interpreted by the server, it is not send to the user.
Thats what PHP is for.
For Example:
You want to make a password login. You write the passwordfunction in php because the user cannot see it.
More Information on PHP
PHP is run by the server that your '.php' file lives on, in this case, your Raspberry Pi. When you request a page from your PI your PHP code will be executed before any HTML is returned to your browser.
You will never see your PHP code in your browser's inspector because your browser never even knows it existed.
If you added something like:
<?php echo "This sentence was written by PHP"; ?>
to your page, you would see the text This sentence was written by PHP in your HTML but you wouldn't see the word echo or the <?php ? tags.
There is a great piece in the PHP docs which explain the three main abilities of PHP. They also have a good guide on how to get started with PHP which may be worth checking out if you are not that familiar with it.
Further Reading:
PHP enabled page
Many people try out codecademy