Page 1 of 1

browers not passing script to PHP

Posted: Wed Feb 02, 2011 10:07 am
by woodplaner
Hello. I can run a PHP script from the URL line by http://localhost/script_name.php. When the same script is embedded into my index.html file, the file runs without executing the php. I understand that the browser is not passing the script to PHP, and the problem is prob a config file. The config files appear to be in place, but I am unsure if it (or they) are located improperly or if the info it contains is not proper or missing.

I am running Apache2 and PHP5. The index.html file is located /var/www/index.html. I appreciate your suggestion to solve this problem.

Thanks

Re: browers not passing script to PHP

Posted: Wed Feb 02, 2011 10:42 am
by Doug G
The obvious solution is "don't put php script in a .html file"

But if you must, you need to configure apache so it understands a .html file needs to go to the php interpreter.

Re: browers not passing script to PHP

Posted: Wed Feb 02, 2011 4:27 pm
by woodplaner
Doug G. Thanks for the reply. I am new to php and html, so my language may be a bit imprecise. By script, I am referring to <?php
phpinfo();
?>
I am surprised at your suggestion not to include php in html files. I thought that was one of the benefits of using php.

How do I change the apache configuration to send .html file to the php interpreter? Is there a particular directive to change?

Thanks

Re: browers not passing script to PHP

Posted: Wed Feb 02, 2011 6:10 pm
by Doug G
apache figures what do with a page based on the file extension. A .html extension doesn't inform apache it needs to send the page through php, so apache doesn't. The .php extension, however, does tell apache to send the page through the php processor.

Somewhere in httpd.conf (or whatever it's called with your apache) you'll find settings that can change how apache interprets an .html page. I don't do this kind of change, I don't know the exact setting.

Re: browers not passing script to PHP

Posted: Wed Feb 02, 2011 6:19 pm
by s.dot
You can embed HTML into a .php file. You cannot embed PHP into an .html file (without special server configuration).

index.html (won't work with php code in it)
index.php (will work with html/php in it)

Assuming apache is correctly configured to parse .php extensions with php

Re: browers not passing script to PHP

Posted: Wed Feb 02, 2011 7:51 pm
by woodplaner
Doug G and s. Dot. The httpd.conf file exists, but there is nothing there, so I will pursue the reason. index.php did run with html and the three lines of php, but it did not work well with the linked css file.

Thanks