follow us on google+ follow us feedburner

FORUM
Please use the search function and/or read the FAQ first.

See code php presented by browser



Posted by: Adam Brave
January 05, 2013 05:30PM
Hi,

When I open php and html files that are stored in the folder "www" the browser presents the html code but not the php code.

If I use the following code for example, I can see the result in the "code tester" but not in a normal page loaded by the browser.

<?php
echo "Current date : ";
echo date("l F d, Y");
?>

Can somebody tell me why?


Regards
Options: ReplyQuote
Posted by: Russell
January 06, 2013 07:30PM
That is very strange, it sounds as if the file type isn't registered in apache to route to the php engine. Since the codetester is working, php is obviously registered in apache.

Are you sure the extension of the file is .php, Notepad has a tendancy to add a .txt to any files it saves. test.php would become test.php.txt if saved in notepad without changing the extension dropdown to be "All files" when saving.

Save this as test.php in your www directory:

<html>
<head>
<title>Test page</title>
</head>
<body>
<span>--|</span><span><?php echo 'php is working'; ?></span><span>|==</span>
</body>
</html>

Make sure there isn't an index page in the www directory so you'll be able to see the directory listing in the following step.

Navigate to 127.0.0.1, you should see all the files and folders in the www directory, click on test.php - what do you see?
Options: ReplyQuote
Posted by: xcpeirano
January 07, 2013 04:39PM
<html>
<head>
<title>Test page</title>
</head>
<body>
<span>--|</span><span><?php echo 'php is working'; ?></span><span>|==</span>
</body>
</html>
Options: ReplyQuote
Posted by: Russell
January 07, 2013 06:34PM
If that is the shown in the browser and the code tester works then my best guess is you haven't saved the file as .php

Use windows explorer and set it to details view (ctrl + shift + 6 in windows 8), this will show the type column. Does the file say "PHP File" in the type column?
Options: ReplyQuote
Posted by: Adam Brave
January 07, 2013 10:46PM
Hi,

It worked, after I have deleted the index file in the www folder, the php code worked just fine. thanks for the help :)
Options: ReplyQuote


Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.