Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this


  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<br />Your ip is is Sunday, 06-Mar-2011 19:25:27 EET Your are using Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: 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 /><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= "" --><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 /><br /><br /><br /><br /><br />
  24. 24. QA<br />