Perl SSI

Introduction

Perl SSI builds off of standard server side includes by allowing code written in the Perl scripting language to be embedded in web pages. As with standard SSI, these directives are processed before they are presented to the web browsing software, so the user does not see the Perl code, only the resultant output.

Also, as with standard SSI, use of these directives is restricted, and they will not work from user personal web sites.


Simple Test

Code:

<!--#perl sub="sub {print qq/If you see this, mod_perl is working!/;}" -->

Output:

If you see this, mod_perl is working!

Code:

Count to 10: <!--#perl sub="sub {for (1..10) {print \"$_ "}}" -->

Output:

Count to 10: 1 2 3 4 5 6 7 8 9 10 

Server Variable Test

Code:

<!--#perl sub="sub {print $ENV{\"SERVER_SOFTWARE\"};}" -->

<P>

<!--#perl sub="sub { if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/) { print 'You are using Internet Explorer as your web browser.'; } elsif ($ENV{'HTTP_USER_AGENT'} =~ /Netscape/) { print 'You are using Netscape as your web browser.'; } elsif ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla/) { print 'You are using Mozilla as your web browser.'; } else { print 'I have no idea what web browser you are using.';};}" -->

Output:

This web server identifies itself as:
Apache/1.3.36 (Unix) mod_jk/1.2.23 PHP/5.2.3 mod_perl/1.29

I have no idea what web browser you are using.


Environment Variables

Code:

<!--#perl sub="sub {foreach (sort keys %ENV) { print \"$_ = $ENV{$_}\n\";}}" -->

Output:


DATE_GMT = Thursday, 28-Aug-2008 14:33:00 GMT
DATE_LOCAL = Thursday, 28-Aug-2008 10:33:00 EDT
DOCUMENT_NAME = perlssi.shtml
DOCUMENT_PATH_INFO = 
DOCUMENT_ROOT = /usr/local/info/sens
DOCUMENT_URI = /services/webhosting/advanced/perlssi.shtml
GATEWAY_INTERFACE = CGI-Perl/1.1
HTTP_ACCEPT = Accept: application/xhtml+xml,text/html;q=0.9,text/plain;
HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_ACCEPT_ENCODING = gzip
HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5
HTTP_CACHE_CONTROL = no-cache
HTTP_CONNECTION = close
HTTP_HOST = www.sens.buffalo.edu
HTTP_PRAGMA = no-cache
HTTP_USER_AGENT = CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
LAST_MODIFIED = Tuesday, 29-Oct-2002 14:09:22 EST
MOD_PERL = mod_perl/1.29
PATH = /usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/ccs/bin:/eng/admin/bin:/usr/local/bin
QUERY_STRING = 
REMOTE_ADDR = 38.103.63.59
REMOTE_PORT = 41701
REQUEST_METHOD = GET
REQUEST_URI = /services/webhosting/advanced/perlssi.shtml
SCRIPT_FILENAME = /usr/local/info/sens/services/webhosting/advanced/perlssi.shtml
SCRIPT_NAME = /services/webhosting/advanced/perlssi.shtml
SERVER_ADDR = 128.205.25.122
SERVER_ADMIN = wwwadmin@eng.buffalo.edu
SERVER_NAME = www.sens.buffalo.edu
SERVER_PORT = 80
SERVER_PROTOCOL = HTTP/1.1
SERVER_SIGNATURE = 
Apache/1.3.36 Server at www.sens.buffalo.edu Port 80
SERVER_SOFTWARE = Apache/1.3.36 (Unix) mod_jk/1.2.23 PHP/5.2.3 mod_perl/1.29 TZ = US/Eastern UNIQUE_ID = SLa3HIDNGQcAAFXHTEc USER_NAME = yearke


Please click here to return to the advanced web page page.

The Powered by UBiquity logo, a link to the UBiquity home page

Valid HTML 4.01! Valid CSS!