Koozali.org: home of the SME Server
Obsolete Releases => SME Server 7.x => Topic started by: girkers on October 31, 2006, 04:00:28 AM
-
When I run this page: phptest.php
<?php
$value = $_SERVER['REMOTE_ADDR'];
print key($_SERVER) . ": $value";
?>
I get the desired result, but when I put that script inside of a HTML file phptest.html it appear not to be parsed through the PHP processor.
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
$value = $_SERVER['REMOTE_ADDR'];
print key($_SERVER) . ": $value";
?>
</body>
</html>
I have even take a simple example straight from the PHP manual and this is not parsed. On both occassions I simply get a blank page with the title of the page.
I have checked both the messages and httpd.error_log logs and there is nothing in them. Any clues?
-
I'm just taking a stab in the dark here, but IIRC Apache looks at the file extension to know what to do with it.
So if you have a file index.html, it will simply serve it to the clients browser without putting it through mod_php to interpret the code, because it thinks its just static html. Whereas if it is a .php file then it will be parsed before before being served.
So either you should use the extension of .php if you want it to be parsed as php, or you need to change the setting in httpd.conf (keeping in mind the whole template thing) to tell Apache to parse .html files as php too.
Of course I could be totally wrong, in which case I'm sure someone will correct me.
8)
-
I'm just taking a stab in the dark here, but IIRC Apache looks at the file extension to know what to do with it.
So if you have a file index.html, it will simply serve it to the clients browser without putting it through mod_php to interpret the code, because it thinks its just static html. Whereas if it is a .php file then it will be parsed before before being served.
So either you should use the extension of .php if you want it to be parsed as php, or you need to change the setting in httpd.conf (keeping in mind the whole template thing) to tell Apache to parse .html files as php too.
Of course I could be totally wrong, in which case I'm sure someone will correct me.
8)
You are completely right. HTML files are not run throught the parser.. PHP files are, even if there is plain HTML code in there. I suggest that you simply rename HTML files with PHP code in it to have the xetension of PHP to get them interpretated by the server.
-
You are great men! :D You were right as simple as that, cheers
-
Alternatively you could put this clause into .htaccess.
<Files phptest.html>
ForceType application/x-httpd-php
</Files>
-
Alternatively you could put this clause into .htaccess.
<Files phptest.html>
ForceType application/x-httpd-php
</Files>
No, that will not do anything. Apache in SME is configured to ignore .htaccess files (as a security precaution).
You can make such changes if required in httpd.conf template fragments - but surely using .php file extensions is easiest.
-
<...but surely using .php file extensions is easiest.>
Agreed. I mentioned it only as an alternative as I don't know the original
poster's full predicament. I currently use the technique to present dynamic
robots.txt files ie on a selective basis depending on various conditions.
-
Renaming the file was my solution in the end and it works a treat, all the CSS and HTML is left and the PHP is executed perfectly.
Thanks again.