View Full Version : SSI replaced by PHP?
05-01-2009, 01:37 AM
I recently learned about Server Side Includes, and got a few working on my pages by adding a .shtml extension (I believe this has to do with the site being hosted on an Apache server). I am trying to get away from using templates and uploading entire sites when they are updated - this is my first step towards dynamic sites I guess.
However, shortly after getting this to work, I read that SSIs were outdated, used in the 90's, and that there was a better suited PHP method for including information throughout an entire site by only updating one file. Are any of you familiar with what this method is? I assume we are not talking about a full blown database here.
I also assume SSIs may be older because I did a forum search and the last post I found on this topic was from 2002.
I just don't want to build an entire site one way when there is a better option.
05-01-2009, 01:49 AM
SSI is quite old. Includes in PHP are much easier:
Simple as that. Save as a .php page, and you're off.
05-01-2009, 02:05 AM
Thank you for the great response. So I have to create a HTML document and then save THAT as a .php file - is I have to call up .php files to the .html document?
The reason I ask this is because I have never created a site with an extension aside from .html. So, it seems odd to me that I could just change the extension to .php, or .asp etc and the page would display the exact same way. Is that the case though?
05-01-2009, 02:09 AM
The extension is generally used to determine how the document is served. So anything that uses php within it will need to be renamed to .php, just like anything with SSI needs a .shtml extension.
What you're including is irrelevant, it can be PHP code, or output simple html (for say a links list).
If you plan on using PHP in the future, I'd just name them .php anyway. That way you won't need to worry about changing it in the future if you want to add code later.
You could also alter you're httpd.conf file (or use a .htaccess) to force .html to be interpreted as .php as well. I wouldn't do that though.
05-01-2009, 02:17 AM
Yeah I was reading about that ".htaccess" edit and it seemed like a quick fix to force something that wasn't supposed to happen...
So, essentially, I could take an existing site and change every extension from .html to .php and the only thing that would change would be the links/addresses?
This is very interesting.
And with a php include I could include a .txt or .html or .js file - whatever as long as my server provided support for that file type?
Would you have to do anything different within this new .php file when it came to adding scripts, etc? Or is that all simply handled by... the server or browser I guess?
You are really helping me out here.
05-01-2009, 02:21 AM
You wouldn't even have to change the addresses. Pointing at home.html would still allow it to parse as PHP code. It is a quick and dirty trick, which is why I don't recommend it. However, unlike a lot of other 'features', this one I would assume is around to stay.
You can include whatever you want. If its PHP code, you're include must be valid PHP code. The server will preprocess what it can and return any results to the main script. If its a text, js, css, html etc type form, it will just include what is in these in the location the include was called. If its a PHP script, it will add the definitions for any classes or functions defined, and import any variables from the include into the main scope. This is what you'll be using include for for the most part.
05-01-2009, 02:22 AM
Excellent - thank you very much.
05-01-2009, 06:43 AM
One other question real quick - lets say a user bookmarks a sites homepage - for example "www.chaosinottawa.org" - if I change the index.html to index.php, will the bookmark be broken or still work?
I ask this because I wonder if it is looking for the index file no matter what the extension is (**since the bookmark would just go to "www.chaosinottawa.org"), or if it is looking for index.html specifically?
05-01-2009, 09:03 AM
If they don't have the index.html in the bookmark, generally the server is set up to target index.php. This is determined by you're apache httpd.conf settings (or IIS equivilent)
DirectoryIndex index.php index.html
Is an example of my home server. If a directory is requested, it will first try to find an index.php file, if not present, the index.html. If both are present, it will go for the index.php (its a first serve first come basis).
You can test it by having an index.html and an index.php with different content to see which gets served.
You can also use mod_rewrite engine to redirect requests against *.html to $1.php instead. If you have a lot of mod_rewrite experience you can use it to set environment variables to determine if they have hit the wrong page, and even remind them to update their bookmarks.
The web is awesome.
05-01-2009, 09:17 AM
Looks like the html page got served first, which is useful knowledge.
Is this something I have control over or is this set by the server administrator(s)?
05-01-2009, 09:21 AM
Yeah, you can change it in an .htaccess file. Just copy the directoryIndex code from above.
The other option is to simply use rewrite until you've gotten rid of all the .html pages.
05-01-2009, 09:24 AM
Well, even if it is set to read .html then .php - I think I will just replace the entire site all at once, you know? I'm going to change it anyway, and as long as it is working I guess why mess with it...
Unless there is a significant speed advantage to changing the file to look for my .php file first.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.