Welcome to DU! The truly grassroots left-of-center political community where regular people, not algorithms, drive the discussions and set the standards. Join the community: Create a free account Support DU (and get rid of ads!): Become a Star Member Latest Breaking News General Discussion The DU Lounge All Forums Issue Forums Culture Forums Alliance Forums Region Forums Support Forums Help & Search

DaveJ

(5,023 posts)
Tue Dec 13, 2011, 03:38 PM Dec 2011

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

13 replies = new reply since forum marked as read
Highlight: NoneDon't highlight anything 5 newestHighlight 5 most recent replies

Response to tabatha (Reply #1)

SirRevolutionary

(579 posts)
2. I think shtml is all about includes
Tue Dec 13, 2011, 03:48 PM
Dec 2011

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)
4. Great link, thanks.
Tue Dec 13, 2011, 04:17 PM
Dec 2011

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)
5. you don't necessarily have to use php, if you want to edit your server config
Tue Dec 13, 2011, 04:20 PM
Dec 2011

and map another mime type to be processed by php.

By default, though, yeah, it needs to be that way.

DaveJ

(5,023 posts)
6. That explains the ambiguity
Tue Dec 13, 2011, 04:41 PM
Dec 2011

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)
7. If you have access to an .htaccess file or your httpd.conf file:
Tue Dec 13, 2011, 04:43 PM
Dec 2011

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)
8. <-- what tranche said. Makes sense
Tue Dec 13, 2011, 04:52 PM
Dec 2011

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.

DaveJ

(5,023 posts)
10. Ok, got it working using the last method
Wed Dec 14, 2011, 05:26 PM
Dec 2011

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)
11. Test it as is. The extensions are becoming less important to the server software, however,
Thu Dec 15, 2011, 11:25 AM
Dec 2011

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)
12. A web page I wrote/edited on this a few years back:
Sun Dec 18, 2011, 04:50 AM
Dec 2011
http://www.php.net/manual/en/security.hiding.php

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.
Latest Discussions»Retired Forums»Website, DB, & Software Developers»Do PHP files need a certa...