$Web Redirect: Difference between revisions
m (1 revision) |
m (1 revision) |
(No difference)
|
Revision as of 19:14, 12 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 (see "Calling Sirius Mods $functions"), and it takes a single required string argument and returns a 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).
|
---|
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.