$Web_Redirect

From m204wiki
Revision as of 21:25, 16 October 2012 by JAL (talk | contribs)
Jump to navigation Jump to search

<section begin="desc" />Re-route client to another server<section end="desc" />

$Web_Redirect re-routes the client to another server.

$Web_Redirect is a callable $function, and it takes a single required string argument and returns a status code.

Syntax

<section begin="syntax" />%rc = $Web_Redirect( url ) <section end="syntax" />

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

Usage notes

  • 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:
    • 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.

Examples

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.