My php script isn't visible in the browser [duplicate] - php

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 just started PHP I got my XAMMP server up and running and now I made my first html test page and added one line of PHP script but it isn't showing in my browser.
<!DOCTYPE html>
<html lang="nl">
<head>
<title>Mijn php-script</title>
</head>
<body>
<?php
phpinfo();
?>
</body>
</html>
It does however shows the title I gave it, can anybody tell me why the rest isn't showing? it should show the info version page of my PHP.

You need to save your file as .PHP and not as .HTML in order to be able to run this. Also, you need to fix the HTML closing tag in the end, as you are closing the HEAD again.

Related

The simplest code not working (built in server) [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 4 years ago.
php7.2
Could you help me understand why my code is not working?
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
Please, have a look at the attached image.
I run the built in server.
On a hunch I will take a guess that you are missing the file extension of .php

Failing to pass variables via URL to php page [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
Im trying to send 2 variables to my php page via a link, i can't figure out what im doing wrong. The outcome is not right. Im expecting just the display of values and instead the whole php code displays.
Thanks for helping in advance, below is my html, php and result.
My html page is named "index.html" and my php "default.php"
HTML:
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Information sänd via adressfältet och länkar</title>
<meta charset="UTF-8">
</head>
<body>
Link
</body>
</html>
php:
<?php
header("Content-Type: text/plain");
echo $_GET["name"];
echo $_GET["gender"];
?>
Result:
<?php
header("Content-Type: text/plain");
echo $_GET["name"];
echo $_GET["gender"];
?>
There are a couple of factors affecting such
first one confirm that your php module is properly configured to Apache and it reads the .php extension
two that your file is actually saved as .php if you are using a text-editor like notepad which appends the .txt file format at the end, unless you select file type as all files
I found the problem thnx to this thread: PHP code is not being executed, instead code shows on the page
The problem was:
Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

PHP seems to run the first line then the rest displays in browser [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 6 years ago.
So I am learning PHP from a book and I understand it is done server side. I installed wampserver and it's running. When I open my php file, it'll run the first line but the rest just displays in the browser. Here's the code:
<!DOCTYPE html>
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo "<p>Order processed at ";
echo date('H:i, jS F Y');
echo "</p>";
?>
</body>
</html>
Here's what displays: Screen Shot
It displays the first 'echo' statement it seems. But the rest... I haven't changed any settings on the wampserver program, I just installed it and made sure all services were started up. Is there something else I need to do?
I'm using Windows 10.
I think PHP doesn't run at all.
Look in your source code in your browser, if you can see <?php your PHP doesn't work.
Create a file "info.php" and write the code: <?php phpinfo(); ?> to test your PHP.

Echo is not working with HTML inside of php but working with php [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 6 years ago.
This is working when I open it with ubuntu terminal
First.php
<?php
echo "My first PHP script!";
?>
But I have made one HTML with Same confiuration
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
When I open it in browser it shows empty
Any help will be appreciated
You need a php extension on any webserver running that parses the script, you cant just input php to an html file and open this one. PHP is a serverside language not a clientside
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
Save this file as for example mytest.php and run on the browser
output is :: My first PHP script
Try it OR you can run it from terminal as well
Always save file with php extension if it has php code for Cor PHP. You can put HTML/javascript/css code inside a filename.php file but outside tags, that will work fine.

My php code gets commented out by the browser [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: Code gets turned into HTML <!— Comments? -->
I have some very, very simple php code.
<html>
<head>
<title>Something</title>
</head>
<body>
<h2>Something</h2>
<?php
$val = $_POST['a'];
echo 'Value: ' . $val . '<br />;
?>
</body>
</html>
When I press the submit button in an form I've made, the browser comments out the php code like this:
<!--?php
//the stuff i do above
?-->
Anyone knows what this is?
Are you using CMS?
This looks like Joomla behavour for PHP code when you just insert it in template without using special module.
PHP is a server-side language. It is evaluated on the server, and the results of the evaluation replace the code itself.
This is by design and it would terrible if the PHP source code for every page were included in the HTML comments (eg you can see database passwords, etc.).
You cannot see PHP from the client (i.e. HTML source).
Yes, you're missing a closing ' at the end of your echo statement.

Categories