12 1 redirection cgi/perl programming by diane zak
TRANSCRIPT
12
1
Redirection
CGI/Perl ProgrammingBy Diane Zak
12
2
Objectives
• In this chapter, you will:
• Include the Location header in a script
• Include the Refresh header in a script
12
3
Introduction• Documents often move on the Web
from one location to another– Link to new URL so user must click to go
to new location– Automatically forward the browser to a
new address• Immediately• After a period of time (seconds)
– META tag – HTML– Location Header – script– Refresh Header - script
12
4
Redirecting a browser• Location header:
– Immediately redirects the browser– Syntax:
• print “Location: url\n\n”;
– Example:print “Location: http://www.rsp.com/public_html/chap12/error.html\n\n”;
• The 1st newline character identifies the end of the Location header
• The 2nd newline character inserts a blank line below the header to signal end of header section
• Location header used instead of Content-type header
12
5
Redirecting a Browser
• Refresh header:– Waits a specified number of seconds before
redirection– Syntax:
• print “Refresh: seconds; URL=url\n”;
– Example:print “Refresh: 3; URL=“http://www.rsp.com/public_html/chap12/error.html\n”;print “Content-type: text/html\n\n”;
• Contains one newline character because it is used with the Content-type header
12
6
Using a Refresh Header
12
7
Using a Refresh Header
• Uses Refresh header to redirect the page in 3 seconds
12
8
Using a Location Header
12
9
Using a Location Header
If no Name was typed into the cara1.html page
12
10
Summary
• You can use the Location header or the Refresh header in a CGI script to redirect the user’s browser to another location.
• The Location header redirects the browser immediately.– Syntax: print “Location: url\n\n”;
• The Refresh header waits for a specified number of seconds until redirection.– Syntax: print “Refresh: seconds; URL=url\n”;– Is used together with the Content-type header