Apache Server Side Includes<br />Ionuț Ştirban<br />
What are server side includes?<br />SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated...
How do Server Side Includes work?<br />When the client requests a document from the SSI-enabled server, specified document...
Configuration<br />To permit SSI on your server, you must have the following directive in srm.conf:<br />AddType text/x-se...
SYNTAX<br /><!--#directive parameter="value"--><br />no space between <!-- and #<br />directives:<br />config<br />include...
Includes<br />You can include a file using:<br /><!--#include virtual="/includes/ssi.txt" --><br /><!--#include file="ssi....
Example<br /><html><br /><head><title>Include example!</title></HEAD><br /><body><br /><h3>News</h3><br /><!--#include fil...
Example<br />News<br />Liverpool threw the Premier League title race wide open once more with a resounding 3-1 win over Ma...
Echo<br />The echo directive returns the value of special SSI variables as well as other environment variables<br />The on...
Example<br /><html><br /><head><title>Echo example!</title></head><br /><body><br /><h3>Welcome to my server at<br /><!--#...
Example<br />Welcome to my server at students.info.uaic.ro<br />Your ip is 92.86.84.57Today is Sunday, 06-Mar-2011 19:25:2...
ECHO EXAMPLES <br /><!--#echo var="DOCUMENT_NAME" --><br /><!--#echo var="DOCUMENT_URI" --><br /><!--#echo var="LAST_MODIF...
Date<br /><!--#echo var="DATE_LOCAL" --><br />Output:<br /><html><body> Sunday, 06-Mar-2011 13:08:03 EET </body></html><br...
Exec<br />The exec command simply executes a program, script or a shell command on the server. It takes two formats "Exec ...
DEMO<br />
Config<br />In addition to being able to config the time format, you can also config two other things:<br />if you want to...
CONFIG EXAMPLES<br /><!--#configsizefmt="bytes" --> <br /><!--#configtimefmt="%y/%m/%d" --><br /><!--#configerrmsg="we hav...
Advanced SSI techniques<br />Using the set directive to set variables for later use:<br /><!--#set var="name" value="Ronal...
Advanced SSI techniques<br />Conditional<!--#if expr='"$DOCUMENT_URI" = "/ssi.shtml"' -->in ssi <!--#elifexpr='"$DOCUMENT_...
WHEN TO USE SSI?<br />The decision of when to use SSI, and when to have your page entirely generated by some program, is u...
ADVANTAGES<br />viewing the document source doesn't reveal their use<br />they are easier and faster to develop (and to ma...
DISAVANTAGES<br />it can be quite costly for a server to continually parse documents before sending them to the client<br ...
bibliography<br />http://httpd.apache.org/docs/current/howto/ssi.html<br />http://oreilly.com/openbook/cgi/ch05_02.html<br...
QA<br />
Upcoming SlideShare
Loading in...5
×

Ssi

381
-1

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
381
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ssi

  1. 1. Apache Server Side Includes<br />Ionuț Ştirban<br />
  2. 2. What are server side includes?<br />SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology.<br />Example:<!--#echo var="SERVER_NAME"--><br />
  3. 3. How do Server Side Includes work?<br />When the client requests a document from the SSI-enabled server, specified document is scanned by the server for the SSI code elements and carry's out the required actions based on the code element<br />
  4. 4. Configuration<br />To permit SSI on your server, you must have the following directive in srm.conf:<br />AddType text/x-server-parsed-html .shtmlor<br />AddType text/html .html<br />In the access configuration file (access.conf) that dictate what type of SSI directives you can place in your HTML document you must have:<br />Options Includes ExecCGI or<br />Options IncludesNoExec<br />
  5. 5. SYNTAX<br /><!--#directive parameter="value"--><br />no space between <!-- and #<br />directives:<br />config<br />include<br />echo<br />exec<br />parameters:<br />virtual, file<br />cmd, cgi<br />timefmt<br />
  6. 6. Includes<br />You can include a file using:<br /><!--#include virtual="/includes/ssi.txt" --><br /><!--#include file="ssi.txt" --><br />"Include virtual" should be used when the path to the document is given relative to the document root.<br />The "Include File" argument is used when the path to the document we want to include is given relative to the shtml file itself.<br />
  7. 7. Example<br /><html><br /><head><title>Include example!</title></HEAD><br /><body><br /><h3>News</h3><br /><!--#include file="news.txt" --><br /></body><br /></html><br />news.txt:<br /><p>Liverpool threw the Premier League title race wide open once more with a resounding 3-1 win over Manchester United at Anfield.</p><br />
  8. 8. Example<br />News<br />Liverpool threw the Premier League title race wide open once more with a resounding 3-1 win over Manchester United at Anfield.<br />
  9. 9. Echo<br />The echo directive returns the value of special SSI variables as well as other environment variables<br />The only parameter to this directive is var, whose value is the name of the variable you wish to echo. <br />Format:<!--#echo var="var name"--><br />
  10. 10. Example<br /><html><br /><head><title>Echo example!</title></head><br /><body><br /><h3>Welcome to my server at<br /><!--#echo var="SERVER_NAME"--></h3><br />Your ip is <br /><!--#echo var="REMOTE_ADDR"--> <br /><br />Date: <!--#echo var="DATE_LOCAL"--> <br /><br />Your are using <br /><!--#echo var="HTTP_USER_AGENT" --><br /></body><br /></html><br />
  11. 11. Example<br />Welcome to my server at students.info.uaic.ro<br />Your ip is 92.86.84.57Today is Sunday, 06-Mar-2011 19:25:27 EET Your are using Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15 <br />
  12. 12. ECHO EXAMPLES <br /><!--#echo var="DOCUMENT_NAME" --><br /><!--#echo var="DOCUMENT_URI" --><br /><!--#echo var="LAST_MODIFIED" --><br /><!--#echo var="REMOTE_USER" --><br /><!--#echo var="DATE_GMT" --><br /><!--#echo var="HTTP_ACCEPT_ENCODING" --><br /> <!--#echo var="HTTP_REFERER" --><br />http://www.ssi-developer.net/ssi/ssi-echo.shtml<br />
  13. 13. Date<br /><!--#echo var="DATE_LOCAL" --><br />Output:<br /><html><body> Sunday, 06-Mar-2011 13:08:03 EET </body></html><br /><!--#configtimefmt="%A, %B %d, %Y" --> <!--#echo var="DATE_LOCAL" --><br />Ouput:<br />Sunday, March06, 2011<br />
  14. 14. Exec<br />The exec command simply executes a program, script or a shell command on the server. It takes two formats "Exec CMD" which is used to run a command and "Exec CGI" which can be used to execute a script.<br /><!--#exec cmd= "ls" --><br /><!--#exec cgi= "counter.pl.cgi" --><br />
  15. 15. DEMO<br />
  16. 16. Config<br />In addition to being able to config the time format, you can also config two other things:<br />if you want to change the error message to something else, you can do so with the errmsg attribute to the config element:<!--#configerrmsg="[This is a message error]" --> <br />you can config the format in which file sizes are returned with the sizefmt attribute:<!--#configsizefmt="bytes"--> <br />
  17. 17. CONFIG EXAMPLES<br /><!--#configsizefmt="bytes" --> <br /><!--#configtimefmt="%y/%m/%d" --><br /><!--#configerrmsg="we have a problem."<br />
  18. 18. Advanced SSI techniques<br />Using the set directive to set variables for later use:<br /><!--#set var="name" value="Ronaldo" --> <br /><!--#set var="modified" value="$LAST_MODIFIED" --><br /><!--#set var="cost" value="$100" --><br /><!--#set var="date" value="${DATE_LOCAL}_${DATE_GMT}" --><br />
  19. 19. Advanced SSI techniques<br />Conditional<!--#if expr='"$DOCUMENT_URI" = "/ssi.shtml"' -->in ssi <!--#elifexpr='"$DOCUMENT_URI" = "/exec.shtml"' -->in exec <!--#else -->in neither<!--#endif --> <br />
  20. 20. WHEN TO USE SSI?<br />The decision of when to use SSI, and when to have your page entirely generated by some program, is usually a matter of how much of the page is static, and how much needs to be recalculated every time the page is served. <br />
  21. 21. ADVANTAGES<br />viewing the document source doesn't reveal their use<br />they are easier and faster to develop (and to maintain) than cgi<br />decrease the chance of introducing errors when changing information<br />
  22. 22. DISAVANTAGES<br />it can be quite costly for a server to continually parse documents before sending them to the client<br />enabling SSI creates a security risk<br />
  23. 23. bibliography<br />http://httpd.apache.org/docs/current/howto/ssi.html<br />http://oreilly.com/openbook/cgi/ch05_02.html<br />http://www.ssi-developer.net/ssi/<br />http://www.wdvl.com/Authoring/SSI/Intro/index.html<br />http://websitetips.com/ssi/<br />
  24. 24. QA<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×