NAME

ASP4::Server - Utility Methods

SYNOPSIS

# Get the full disk path to /contact/form.asp:
$Server->MapPath("/contact/form.asp");

# Email someone:
$Server->Mail(
  To      => 'jim@bob.com',
  From    => 'Joe Jangles <joe@jangles.net>',
  Subject => 'Test Email',
  Message => "Hello There!",
);

# Avoid XSS:
<input type="text" name="foo" value="<%= $Server->HTMLEncode( $Form->{foo} ) %>" />

# Proper URLs:
<a href="foo.asp?bar=<%= $Server->URLEncode($Form->{bar}) %>">Click</a>

DESCRIPTION

The $Server object provides some utility methods that don't really fit anywhere else, but are still important.

PUBLIC METHODS

HTMLEncode( $str )

Performs a simple string substitution to sanitize $str for inclusion on HTML pages.

Removes the threat of cross-site-scripting (XSS).

Eg:

<tag/>

Becomes:

&lt;tag/&gt;

HTMLDecode( $str )

Does exactly the reverse of HTMLEncode.

Eg:

&lt;tag/&gt;

Becomes:

<tag/>

URLEncode( $str )

Converts a string for use within a URL.

eg:

test@test.com

becomes:

test%40test.com

URLDecode( $str )

Converts a url-encoded string to a normal string.

eg:

test%40test.com

becomes:

test@test.com

MapPath( $file )

Converts a relative path to a full disk path.

eg:

/contact/form.asp

becomes:

/var/www/mysite.com/htdocs/contact/form.asp

Mail( %args )

Sends email - uses Mail::Sendmail's sendmail(...) function.

RegisterCleanup( \&code, @args )

The supplied coderef will be executed with its arguments as the request enters its Cleanup phase.

See http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlCleanupHandler for details.