joePHP Posted January 15, 2009 Share Posted January 15, 2009 Hi, I always thought that in order for the server to execute PHP code, you need to save the file as a PHP extension (.php) However, today I opened an existing sites index.html file and there is PHP code in it and it's getting executed properly. I was wondering if it's and option I could set in the ini.php file? or it's the server that is doing it? Thanks, Joe Quote Link to comment https://forums.phpfreaks.com/topic/140879-php-or-html/ Share on other sites More sharing options...
revraz Posted January 15, 2009 Share Posted January 15, 2009 You can set your webserver to parse HTML files as PHP. Quote Link to comment https://forums.phpfreaks.com/topic/140879-php-or-html/#findComment-737371 Share on other sites More sharing options...
.josh Posted January 15, 2009 Share Posted January 15, 2009 How did you open this file? Did you do it through your browser (like, view source)? If it's executing properly, and you can see the code from your browser, then it's not php. As revraz mentioned, you can set your server to treat any file extension as anything you want. But if you set a .html file to parse php, it still gets parsed on the server, just like a normal php file. Only the results would be sent to your browser. Quote Link to comment https://forums.phpfreaks.com/topic/140879-php-or-html/#findComment-737380 Share on other sites More sharing options...
cwarn23 Posted January 15, 2009 Share Posted January 15, 2009 Why not use the apache rewrite mod. Just simply make all html extensions redirect to php extensions without the user knowing it. So place the following in a file name '.htaccess' (nothing before the dot and without the quotes). RewriteEngine On RewriteRule ^(.*)\.html$ $1.php RewriteRule ^(.*)\.htm$ $1.php That is a very simple .htaccess file and believe me they can get complex when you want each php file to have $_GET[] variables. And another method which wikipedia uses is editing the apache httpd.conf file for simular rewrite rules. From those 2 methods I recommend the .htaccess as you can't wreck the server no matter what you do with the .htaccess file unlike the httpd.conf file. Quote Link to comment https://forums.phpfreaks.com/topic/140879-php-or-html/#findComment-737412 Share on other sites More sharing options...
RussellReal Posted January 15, 2009 Share Posted January 15, 2009 cwarn a much easier (less redundant) option is to add .htm and .html to PHP's extensions AddType application/x-httpd-php .html .htm ^^ add that into your .htaccess file and all your .html and .htm files will evaluate php Quote Link to comment https://forums.phpfreaks.com/topic/140879-php-or-html/#findComment-737483 Share on other sites More sharing options...
lordphate Posted January 15, 2009 Share Posted January 15, 2009 I agree with RussellReal, that is what i do. Quote Link to comment https://forums.phpfreaks.com/topic/140879-php-or-html/#findComment-737487 Share on other sites More sharing options...
Yesideez Posted January 15, 2009 Share Posted January 15, 2009 Just be warned that if the mod_rewrite/addtype stops working for whatever reason then the PHP scripts can be downloaded and viewed within the HTML without being executed. Best to keep the .php extension and use mod_rewrite to make it look like .html. Quote Link to comment https://forums.phpfreaks.com/topic/140879-php-or-html/#findComment-737575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.