Do PHP files need a certain extension, like .php?
I need to insert a little script that reads from a Wordpress blog, and then displays a blogroll on our main webpage. Everything is on the same server. The person that created the website made the main page index.shtml. Do I need to change it to index.php to get PHP scripts to work?
Thanks,
Dave
Anything with php in it, has to have the extension, e.g.
index.php
Although post 2 indicates otherwise, I'll try both ways and see how it goes.
Thanks
Response to tabatha (Reply #1)
Tesha This message was self-deleted by its author.
SirRevolutionary
(579 posts)I don't think you need to change any extensions to php at all. Take a look at the source code for that index.shtml page first and see how they include other scripts. This link might help http://rssfeedreader.com/portal/php
DaveJ
(5,023 posts)This obviously is my first PHP endeavor, so that really helps. I'll get back to you all with the results. Thanks again.
ixion
(29,528 posts)and map another mime type to be processed by php.
By default, though, yeah, it needs to be that way.
DaveJ
(5,023 posts)Hopefully I can edit the server config. I'm not sure though, since it's a shared server. I will see. Thanks.
tranche
(929 posts)You can add something like this:
AddType application/x-httpd-php .shtml
Basically, you can indeed execute PHP code in just about any filetype if you specify it.
http://stackoverflow.com/questions/1581765/can-we-include-php-file-in-html-file
http://stackoverflow.com/questions/1672391/html-php-do-i-need-to-change-the-extension-of-html-file
or you could just have your PHP script spit out a .shtml (.inc) file and include that in your index.shtml file.
SirRevolutionary
(579 posts)You can call it ".whatever" as long as the server knows that its really executable PHP. It's been a while, but I'm pretty sure I have some .info files that hold PHP scripts for some of my sites, and they're used as includes. Most likely, that's built into Zend framework or something else I've used, or it's already set up in my Zend config files, but as long as the server configs knows what to expect it should work fine.
greyl
(22,997 posts)DaveJ
(5,023 posts)I added <!--#include virtual="/blog_roll.php" --> to the SHTML page and put my code in blog_roll.php.
PHP is not enabled by default in SHTML files, and I did not feel like going into .htaccess. I've done that to do a bunch of 301 redirects but it's not really necessary here (long story but the ISP's control panel is firewalled from our network). Using the include is nice and clean.
Thanks!
HopeHoops
(47,675 posts)they are still extremely important to the developer. I use them on Mac & Linux even though they aren't necessary just to give me a clue as to what kind of file I'm dealing with. Double-clicking on damn near anything usually brings up an appropriate application now.
boppers
(16,588 posts)You can even use ".bop" as a file extension... it's a little vanity joke I put into the official documentation. Basically, the extension just needs to be mapped to an application.