Hi Andrew,
I've been working on a similar question recently. Try to set the cookie and
then redirect back into the same script. When setting the cookie, also place
a temporary value in the CGI environment. When the script is activated the
second time around, the presence of the temporary CGI value indicates our
attempt to set a cookie. If there is no cookie and the temporary value
exists, it basically means that the remote browser is not accepting our
cookie. BTW, I gained a lot of insight regarding this issue by reading a
Randal Schwartz tutorial at the following URL:
http://www.stonehenge.com/merlyn/WebTechniques/col61.html
and I know that the author frequently hovers around this newsgroup so I just
want to say thank you Randal for your excellent articles.
Ibrahim Dawud
Here is a sample of my code which is based on that tutorial:
my $visitor_cookie = $cgi->cookie(-name=>'site-visitor');
my $visitor_param = $cgi->param ("site-visitor");
if (!defined $visitor_cookie){
if (!defined $visitor_param){
# Try to start a new session by setting a "site-visitor"
# cookie. If that fails, place the session in the CGI environment.
$visitor_cookie = $cgi->cookie
-name=>"site-visitor",-value=>"value");
if (!defined $cgi->param("cookietemp")) {
# Try to create a "site-visitor" cookie for the first time.
# Exit the script using redirect and come back to check if it is
there.
# Set a temporary value in the CGI environment.
$cgi->param("cookietemp",1);
print $cgi->redirect(-cookie=> $visitor_cookie, -uri=>
$cgi->self_url());
}
else {
# We know if we are here that we failed to create a
"site-visitor"
# cookie the first time we ran this script. Place the session
data
# in the CGI environment instead.
$cgi->param("site-visitor","value");
print $cgi->redirect(-uri=> $cgi->self_url());
}
}
else {
# Basically, the previous session was passed via CGI. It is
# reasonable to continue using CGI to pass along session data. This
# means making sure that all links and hidden fields have a
# unique identifier embedded in them to pass on.
if (!defined $cgi->param("cookietemp")) {
# subsequent times using CGI
}
else {
# first time using CGI
$cgi->delete("cookietemp");
print $cgi->redirect(-uri=> $cgi->self_url());
}
}
else {
# previous session was passed via a cookie. Question: Is it necessary
# to also check CGI parameters at this point? Probably not since
# we have assumed cookies as the primary method for passing session
# data.
if (!defined $cgi->param("cookietemp")) {
# subsequent times using cookies
}
else {
# first time using cookies
$cgi->delete("cookietemp");
print $cgi->redirect(-uri=> $cgi->self_url());
}
}
----- Original Message -----
From: "Andrew" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 27, 2001 4:27 AM
Subject: Cookie and redirecting.
> Dear Folks,
>
> I am currently working on cookies for tesing out.
> Although a lot of people had disabled the function on
> their browsers, I would just like to try it.
>
> I got few knotty problems :
>
> 1) I could set the cookie's parameters and
> retrieve it. But how I can make use of the returned
> parameters to realise the concept of cookie.
>
> 2) Upon detecting that the cookie is not valid
> using if statement, I would like to use the command in
> the CGI script to immediate load another URL page. I
> had tried the redirect command for cookie but could
> not help.
>
> E.g. if ($cookieID eq '12345') {
>
> #load new web page.
>
> }
>
> Thanks,
> Andrew
>
>
> ____________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
> or your free @yahoo.ie address at http://mail.yahoo.ie
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]