12 1 redirection cgi/perl programming by diane zak

10
12 1 Redirection CGI/Perl Programming By Diane Zak

Upload: hope-mccormick

Post on 31-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 12 1 Redirection CGI/Perl Programming By Diane Zak

12

1

Redirection

CGI/Perl ProgrammingBy Diane Zak

Page 2: 12 1 Redirection CGI/Perl Programming By Diane Zak

12

2

Objectives

• In this chapter, you will:

• Include the Location header in a script

• Include the Refresh header in a script

Page 3: 12 1 Redirection CGI/Perl Programming By Diane Zak

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

Page 4: 12 1 Redirection CGI/Perl Programming By Diane Zak

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

Page 5: 12 1 Redirection CGI/Perl Programming By Diane Zak

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

Page 6: 12 1 Redirection CGI/Perl Programming By Diane Zak

12

6

Using a Refresh Header

Page 7: 12 1 Redirection CGI/Perl Programming By Diane Zak

12

7

Using a Refresh Header

• Uses Refresh header to redirect the page in 3 seconds

Page 8: 12 1 Redirection CGI/Perl Programming By Diane Zak

12

8

Using a Location Header

Page 9: 12 1 Redirection CGI/Perl Programming By Diane Zak

12

9

Using a Location Header

If no Name was typed into the cara1.html page

Page 10: 12 1 Redirection CGI/Perl Programming By Diane Zak

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