Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post

    SSI replaced by PHP?

    Hello all.
    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.

    Any ideas?
    Thanks.
    I just don't want to build an entire site one way when there is a better option.
    -AJ

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    SSI is quite old. Includes in PHP are much easier:
    PHP Code:
    <!DOCTYPE ...>
    <html>
    ...
    <body>
    <?php include('/path/to/include.ext');?>
    </body>
    Simple as that. Save as a .php page, and you're off.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    ajhauser (05-01-2009)

  • #3
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    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?
    Last edited by ajhauser; 05-01-2009 at 02:08 AM. Reason: Clarification of my ignorance.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    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?

    Many thanks!!
    You are really helping me out here.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    ajhauser (05-01-2009)

  • #7
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    Excellent - thank you very much.

  • #8
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    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?

    Thanks!
    Last edited by ajhauser; 05-01-2009 at 07:01 AM. Reason: Clarify

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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)
    Code:
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #10
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    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)?

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    ajhauser (05-01-2009)

  • #12
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    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.
    Last edited by ajhauser; 05-01-2009 at 09:45 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •