A blog & community for non-professional web designers, programmers, webmasters, and other web savvies.

Simple Server Side Includes Codes

February 4, 2011 - 12:00am -- Thomas

In this article I show you how you can make your pages more dynamic with the use of server side includes.

In my last article I talked about using server side includes to include your sites layout on every page of your site. In this article I will be showing you some other stuff you can do with server side includes.

Does my server support server side includes?

If you are unsure whether your server supports SSI create a file called test.shtml. Copy and paste this code into your file:

<!--#echo var="DATE_LOCAL" -->

If you do see a blank page unfortunately your server does not have SSI enabled. If the page is not blank and shows the current time set on the server SSI is enabled on your server!

** These codes will only work if the page extension is .shtml **

Display Users IP Address

Your IP Address is: <!--#echo var="REMOTE_ADDR" -->

This will display the visitors IP address.

Display File Last Modified Date

<!--#config timefmt="%a. %B %d, %r %Z" -->
Page Last Modified: <!--#echo var="LAST_MODIFIED" -->

This will return the time you last saved the file. The time is likely in EST depending on the time set on your server. You can change the format for the time. Here's good time format chart here. You need to change the code that looks like this:

<!--#config timefmt="%a. %B %d, %r %Z" -->

Display Referring Page

You came to this page from: <!--#echo var="HTTP_REFERER" -->

This will return the full page URL.

Display Current Date

<!--#config timefmt="%a. %B %d, %r %Z" -->
<!--#echo var="DATE_LOCAL" -->

The time varies depending on the time set on your server. If your server clock is set correctly it should be EST time. You can change the format for the time. Here's a good time format chart here. You need to change the code that looks like this:

<!--#config timefmt="%a. %B %d, %r %Z" -->

Display File Name

<!--#echo var="DOCUMENT_NAME" -->

This will display the file name of the current file including the extension.

Display Users Browser

You are using <!--#echo var="HTTP_USER_AGENT" -->

This does not only display the browser name but other information about the users operating system.

Display Server IP Address

Server IP Address: <!--#echo var="SERVER_ADDR" -->

There are some other simple SSI codes you can use to make your pages more dynamic but I only included the most useful codes in this blog post.

Thanks for reading. If you have any questions or comments please post them below.

Forum Board: 

@IceCaves on Twitter

    Stay Connected

    Twitter Facebook Tumblr Google+ Glaciallis Google RSS

    *Follow us on Twitter or Facebook to also follow minor site updates that don't make it to the homepage news.