home / experts / perl / tutorial / 7 |
|
|
URL Redirects with CGI.pmCGI.pm redirect()Fortunately, we can whip up a short Perl script
that will glean this information for us and drop it in the Web log.
The CGI module provides a For example, we would use the following HTML link to redirect a user to http://internet.com:
The string after the To figure out how to encode a URL, simply read RFC 2396 at http://www.ietf.org/rfc/rfc2396.txt. You can skip the informative reading by using a CGI script I wrote to encode a URL. It's available at http://www.webreference.com/cgi-bin/perl/7/encode.pl. Once you have your encoded URL, all you need to do is add it to the end of the redirect.pl URL, pre-pended by a ?. The CodeWell, it's time to examine the source. The script evolved into 50 lines of code including the copyright. Lines 1-10 contain the shebang and copyrights; the GNU copyright that is. Lines 12-15 load our modules. You'll notice that we're
loading the As with any Web application, there's always a potential for abuse.
Our two constants (lines 18-23),
Now we create a new instance of the CGI module on line 26. On line 29, we call the Then on line 32, we check for a referer URL by testing
See? Next, we grab the referer URL on line 35 so we
can check if the referer host is in our Lastly, we redirect the client to the url specified by The end result is that we have a line in our log file that we can evaluate. It might look something like this:
And in case you're breaking into a cold sweat looking at that encoded URL, the
|
home / experts / perl / tutorial / 7 |
|
Produced by Jonathan
Eisenzopf and
Created: August 18, 1999
Revised: August 18, 1999
URL: http://www.webreference.com/perl/tutorial/7/