302: Server Side Includes: An Introduction
What is Server Side Includes?
Server side includes (SSI) are ways of manipulating web pages at the server level before they are sent to the visitor’s web browser. SSI uses tags so when the information is parsed, it cuts and pastes the information from another source into the webpage. Here’s what happens:
- The server reads the document and parses it for directives.
- Follows the instructions (directives) that it finds and merges the results into a final document to deliver to the client's browser
- The final document is sent to the client browser for viewing.
Why are Server Side Includes Important?
If you have a lot of web pages and want to include information on all of them, this can be a huge asset. Instead of having to update all of your pages, you would just need to update your include file. So let’s say you use SSI for your footer on all your webpages. If you needed to make changes to the footer, you’d only have to update the includes file to do so.
Creating a "Hello World" SSI page
- The first step is to log into cPanel. We'll be creating two files for this example. Both files can be created using file manager within cPanel. The first file you will need to create is the helloworld.shtml file. Be sure you name the file with the correct file extension "shtml" or it will not work.
- Once the file is created you'll need to use "code edit" to insert the following code into the file.
- Next, you'll need to create the actual "include" file called "helloworld.php" This file contains the directives to be included in the webpage calling the include file. Make sure both files are in the same location or folder for this example to work.
<!--#include virtual="helloworld.php?var=Hello%20World" -->
<?php $variable=$_GET['var']; echo $variable; ?>
So now, lets review whats happening during the SSI. The first file you created is including the file called "helloworld.php". The SSI include in our original file sets the variable for the PHP code. The code in the php file that is included tells the webpage to print the variable to the screen.
So as the server reads the initial file and finds that it includes the PHP file we created it loads that. It then parses the code and now knows to "echo" or print the variable defined in the original file based on the SSI. The end result is the variable "hello world" is printed on the screen.
If your SSI is successful you should see something similar to the screen shot below:
If you need further assistance please feel free to contact our support department.
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
Post a Comment
Do you want to publish a tutorial to our support center?