Apache Guide: Introduction to Server Side Includes, Part 2 Page 2

And you can config the format in which file sizes are returned with the sizefmt attribute. You can specify bytes for a full count in bytes, or abbrev for an abbreviated number in Kb or Mb, as appropriate.

Executing Commands

I expect that I'll have an article some time in the coming months about using SSI with small CGI programs. For now, here's something else that you can do with the exec element. You can actually have SSI execute a command using the shell (/bin/sh, to be precise--or the DOS shell, if you're on Win32). The following, for example will give you a directory listing.

        <!--#exec cmd="ls" -->

or, on Windows

        <!--#exec cmd="dir" -->

You might notice some strange formatting with this directive on Windows, because the output from dir contains the string "<dir>" in it, which confuses browsers.

Note that this feature is exceedingly dangerous, as it will execute whatever code happens to be embedded in the exec tag. If you have any situation where users can edit content on your web pages, such as with a guestbook, for example, make sure that you have this feature disabled. You can allow SSI, but not the exec feature, with the IncludesNOEXEC argument to the Options directive.

What's Next?

In the next column, I'll talk about some of the more advanced features of SSI, in particular, the flow-control feature (conditional statements) and using variables.

Rich Bowen is the Director of Web Application Development at The Creative Group and the author of Apache Server Unleashed.

This article was originally published on Jun 19, 2000
Page 2 of 2

Thanks for your registration, follow us on our social networks to keep up-to-date