Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199908

Re: [PHP3] page redirection _after_ some seconds From: Derek Sivers (list <email protected>)
Date: 08/25/99

> How do I redirect a user to another page _after_ some (HTML) text has been
> sent (in other words: Header("Location: xxxxxx"); wont do)

HERE'S A CGI SCRIPT THAT WORKS WELL FOR ME EVERY DAY.
You'll see my custom message near the bottom ("Close this window to
come back to CD Baby")

TO SEE IT IN ACTION, GO TO...
http://cdbaby.com/hitme
... and click on the green "MP3" button on the right.

Derek Sivers, CD Baby
http://www.cdbaby.com

----------------

 
 #!/usr/bin/perl
#
# REDIR.PL 1.0 April 9, 1997
# Copyright (C) 1997 John Watson
# e-mail: john <email protected>
#
# -----About-----
# REDIR.PL is a simple little CGI script that will redirect browsers to
# a new URL. It can display a page telling the user they are about to be
# redirected as well as log the redirect. This can be useful for
tracking
# clicks through a web site or just a nice way to say adios to folks
# leaving your site.
#
# The latest copy of this script and documentation can be obtained from
# http://www.watson-net.com/
#
# Parameters
# url:
# fully qualified URL to redirect the user to. the url must be
# fully qualified (http://...) in order to redirect to another
server.
# this also allows you to redirect using different protocols (e.g.
# ftp://..., gopher://..., etc.).
# title:
# title of the new URL for display purposes.
#
# url and title can be passed via POST or GET.
#
# both arguments are optional. if url is blank, the user will
# be redirected to the root of the current server. if title is blank,
# it is set equal to url.
#
# Output
# Creates a web page with the REFRESH meta tag.
# Redirects the user to the new page after n seconds.
# Optionally displays a redirection message to the user.
# Optionally logs all redirects.
#
# Examples
# FORM:
# <form method="POST" action="/cgi-bin/redir.pl">
# <input type="image" value="redir.gif">
# <input type="hidden" name="url" value="protocol://path/file">
# <input type="hidden" name="title" value="URL Title">
# </form>
#
# ANCHOR:
# <a href="/cgi-bin/redir.pl?url=protocol://path/file&title=URL
Title">URL Title</a>
#
# -----Distribution-----
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

require 'ctime.pl';
use CGI;
$q = new CGI;

#
# DEFAULT VARIABLES SECTION
#
$log = 1; # 1 log, 0 no log
$logfile = 'redir.log';
$delay = 1; # delay in seconds. $delay=0, $output=0 work well together.
$output = 1; # 1 output, 0 no output
#
# END OF DEFAULT VARIABLES
#

# get the parameters from the form or url
$url = $q->param('url');
$title = $q->param('title');

# if $url is blank then set equal to root of current server
if ($url eq "") {
    $url = 'http://'.$q->server_name().'/';
}

# if $title is blank then set equal to $url
if ($title eq "") {
    $title = $url;
}

# print html header
header();

# if output requested, print body
if ($output) { body(); }

# print html footer
footer();

# if logging requested, add a log entry
if ($log) { addlog(); }

exit(0);

# the http-equiv line in the header actually does the redirect
sub header {
        print $q->header;
    print <<EOT;
<html>
<head>
<title>Redirect to $title</title>
<meta http-equiv="refresh" content="$delay; url=$url">
</head>

<body bgcolor="#FFFF00" text="navy">

EOT
}

sub body {
    print <<EOT;
<center><BR><BR>
<font face="Tahoma, Verdana, sans-serif" size=7><b>CLOSE THIS WINDOW
WHEN YOU'RE DONE<br>to come back to CD Baby</B></font></center>
EOT
}

sub footer {
    print <<EOT;

</body>
</html>

EOT
}

sub addlog {
    # get localtime()
    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);

    # make all numbers in the date two digits
    if ($sec < 10) { $sec = "0$sec"; }
    if ($min < 10) { $min = "0$min"; }
    if ($hour < 10) #!/usr/bin/perl
#
# REDIR.PL 1.0 April 9, 1997
# Copyright (C) 1997 John Watson
# e-mail: john <email protected>
#
# -----About-----
# REDIR.PL is a simple little CGI script that will redirect browsers to
# a new URL. It can display a page telling the user they are about to be
# redirected as well as log the redirect. This can be useful for
tracking
# clicks through a web site or just a nice way to say adios to folks
# leaving your site.
#
# The latest copy of this script and documentation can be obtained from
# http://www.watson-net.com/
#
# Parameters
# url:
# fully qualified URL to redirect the user to. the url must be
# fully qualified (http://...) in order to redirect to another
server.
# this also allows you to redirect using different protocols (e.g.
# ftp://..., gopher://..., etc.).
# title:
# title of the new URL for display purposes.
#
# url and title can be passed via POST or GET.
#
# both arguments are optional. if url is blank, the user will
# be redirected to the root of the current server. if title is blank,
# it is set equal to url.
#
# Output
# Creates a web page with the REFRESH meta tag.
# Redirects the user to the new page after n seconds.
# Optionally displays a redirection message to the user.
# Optionally logs all redirects.
#
# Examples
# FORM:
# <form method="POST" action="/cgi-bin/redir.pl">
# <input type="image" value="redir.gif">
# <input type="hidden" name="url" value="protocol://path/file">
# <input type="hidden" name="title" value="URL Title">
# </form>
#
# ANCHOR:
# <a href="/cgi-bin/redir.pl?url=protocol://path/file&title=URL
Title">URL Title</a>
#
# -----Distribution-----
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

require 'ctime.pl';
use CGI;
$q = new CGI;

#
# DEFAULT VARIABLES SECTION
#
$log = 1; # 1 log, 0 no log
$logfile = 'redir.log';
$delay = 1; # delay in seconds. $delay=0, $output=0 work well together.
$output = 1; # 1 output, 0 no output
#
# END OF DEFAULT VARIABLES
#

# get the parameters from the form or url
$url = $q->param('url');
$title = $q->param('title');

# if $url is blank then set equal to root of current server
if ($url eq "") {
    $url = 'http://'.$q->server_name().'/';
}

# if $title is blank then set equal to $url
if ($title eq "") {
    $title = $url;
}

# print html header
header();

# if output requested, print body
if ($output) { body(); }

# print html footer
footer();

# if logging requested, add a log entry
if ($log) { addlog(); }

exit(0);

# the http-equiv line in the header actually does the redirect
sub header {
        print $q->header;
    print <<EOT;
<html>
<head>
<title>Redirect to $title</title>
<meta http-equiv="refresh" content="$delay; url=$url">
</head>

<body bgcolor="#FFFF00" text="navy">

EOT
}

sub body {
    print <<EOT;
<center><BR><BR>
<font face="Tahoma, Verdana, sans-serif" size=7><b>CLOSE THIS WINDOW
WHEN YOU'RE DONE<br>to come back to CD Baby</B></font></center>
EOT
}

sub footer {
    print <<EOT;

</body>
</html>

EOT
}

sub addlog {
    # get localtime()
    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);

    # make all numbers in the date two digits
    if ($sec < 10) { $sec = "0$sec"; }
    if ($min < 10) { $min = "0$min"; }
    if ($hour < 10) { $hour = "0$hour"; }
    if ($mon++ < 10) { $mon = "0$mon"; }
    if ($mday < 10) { $mday = "0$mday"; }

    # get remote host dns name or ip address
    $host = $q->remote_host();

    # get ctime() and chop off trailing newline
    chop($time = ctime(time));

    # open the logfile for appending
    open(o,">>$logfile");

    # each print() below is an alternative log format. only one should
    # ever be uncommented.
    # print o "$host\t$mon/$mday/$year\t$hour:$min:$sec\t$url\n";
    print o "$host\t$time\t$url\n";

    # close the logfile
    close(o);
}{ $hour = "0$hour"; }
    if ($mon++ < 10) { $mon = "0$mon"; }
    if ($mday < 10) { $mday = "0$mday"; }

    # get remote host dns name or ip address
    $host = $q->remote_host();

    # get ctime() and chop off trailing newline
    chop($time = ctime(time));

    # open the logfile for appending
    open(o,">>$logfile");

    # each print() below is an alternative log format. only one should
    # ever be uncommented.
    # print o "$host\t$mon/$mday/$year\t$hour:$min:$sec\t$url\n";
    print o "$host\t$time\t$url\n";

    # close the logfile
    close(o);
}

-- 
PHP 3 Mailing List <http://www.php.net/>
To unsubscribe, send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
To contact the list administrators, e-mail: php-list-admin <email protected>