$Web Redirect: Difference between revisions
m (1 revision) |
mNo edit summary |
||
Line 6: | Line 6: | ||
$Web_Redirect re-routes the client to another server. | $Web_Redirect re-routes the client to another server. | ||
==Syntax== | ==Syntax== | ||
<p class="syntax"><section begin="syntax" /> % | <p class="syntax"><section begin="syntax" />%rc = $Web_Redirect( url ) | ||
<section end="syntax" /></p> | <section end="syntax" /></p> | ||
$Web_Redirect is a | $Web_Redirect is a [[Calling_Sirius_Mods_$functions|callable]] $function, and it takes a single required string argument and returns a status code. | ||
===Syntax terms=== | |||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%rc</th> | |||
<td>A numreic [[#Status codes|status code]]. | |||
<tr><th>url</th> | <tr><th>url</th> | ||
<td>An absolute or relative Universal Resource Locator (URL). ''url'' must be non-null (in order for the browser to complete the redirection request). < | <td>An absolute or relative Universal Resource Locator (URL). ''url'' must be non-null (in order for the browser to complete the redirection request). | ||
</td></tr></table> | <p> | ||
'''Note:''' This argument may be a longstring with a length greater than 255 bytes.</p> | |||
</td></tr> | |||
</table> | |||
===Status codes=== | |||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>Code</th> | <tr><th>Code</th> |
Revision as of 21:20, 16 October 2012
<section begin="desc" />Re-route client to another server<section end="desc" />
$Web_Redirect re-routes the client to another server.
Syntax
<section begin="syntax" />%rc = $Web_Redirect( url ) <section end="syntax" />
$Web_Redirect is a callable $function, and it takes a single required string argument and returns a status code.
Syntax terms
%rc | A numreic status code. |
---|---|
url | An absolute or relative Universal Resource Locator (URL). url must be non-null (in order for the browser to complete the redirection request).
Note: This argument may be a longstring with a length greater than 255 bytes. |
Status codes
Code | Meaning |
---|---|
0 | Redirection request initiated. |
-1 | Invalid call, not a Web thread |
-3 | Invalid URL or missing argument |
If the input URL is absolute, processing can be redirected to a different machine or a different port on the same machine (for example, an SSL port). If the URL is relative (no hostname specified), processing is re-directed to the same port but for a different URL. While this might seem like an odd thing to do, it can actually be quite useful for a couple of reasons.
- Browsers cache data based on the URL that actually return data so if the output from several different URLs produce the same output, it can be more efficient for these URLs to all redirect to the same URL than for the each URL to send the response data without a redirect.
- It can simplify coding: one part of an application might process input and then redirect to a separate application that sends a web page to the browser.
Sample code follows:
%DOWNLOAD_TYPE = $Web_Form_Parm('DOWNLOAD_TYPE') IF %DOWNLOAD_TYPE EQ 'FTP' THEN IF $Web_Form_Parm('LOCATION') EQ 'USA' THEN %X = $Web_Redirect('ftp://www.widgets.usa.com') ELSE %X = $Web_Redirect('ftp://www.widgets.ja') END IF END IF
In this example, users that specified a 'DOWNLOAD_TYPE' of 'FTP' on their form are routed to either the Widget Company's USA ftp server or their international server in Japan, depending on the contents of the LOCATION form field.