|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Checking for Cookie Code
I've taken over the management of a site that has a problem with validating cookies. I've found the problem only happens with certain combinations of browser v. and OS v. The cookie set's fine but sometimes a user will get a message saying cookies aren't enabled even when they are. Below is the code that tells the browser to go to the 'nocookie' page. Is this code the best way to check for the existence of the cookie? Is it missing a print statement somewhere and if this is incorrect what's a better way to do this and why? This is probably pretty basic, I'm pretty adept at PHP but never messed around with Perl.
$theCookie = $ENV{'HTTP_COOKIE'}; if ($theCookie !~ /orderID/) { print "Location: http://www.pet-safe.com/Products/nocookies.html\n\n"; |
|
#2
|
|||
|
|||
|
jackmack,
Check out Perl's page regarding CGI::Cookie at, URL It is a good starting point and may help you get off on the right foot. Hope this helps you out some. |
|
#3
|
||||
|
||||
|
So is the code I posted previously not the best way to do it? Would this cause problems with certain browsers?
Can I replace... $theCookie = $ENV{'HTTP_COOKIE'}; if ($theCookie !~ /orderID/) { print "Location: http://www.pet-safe.com/Products/nocookies.html\n\n"; } With... %cookies = fetch CGI::Cookie; foreach (keys %cookies) { if($cookies{$_} != /orderID/) { print "Location: http://www.pet-safe.com/Products/nocookies.html\n\n"; } } Will this work better, or should the existing code work. Am I barking up the wrong tree? |
|
#4
|
||||
|
||||
|
I would suggest using the CGI.pm module, which is a standard module with Perl, 5.03+. Makes it fairly simple to check for the cookie:
Code:
use CGI qw(:standard); my $cgi = new CGI(); my $rediret = "http://www.pet-safe.com/Products/nocookies.html"; my $theCookie = $cgi->cookie(orderID); !defined($theCookie) and $cgi->redirect(-location=>,"$redirect"); exit(); So if the cookie "orderID" is not defined(or found), then redirect them ![]() Quote:
__________________
Thunder Rain Internet Publishing Custom Programming & Database development Providing Personal/Business Internet Solutions that work! |
|
#5
|
||||
|
||||
|
Alright, the cookie is set on one page and checked on two other pages. Short of re-writing the code and using a different module, should the code posted above work.
I'm very appreciative of the help offered above, but I'd rather get the thing working as it is currently constituted. Then move on and re-write it in PHP. But I have to fix the bug in the code I've inherited first. |
|
#6
|
||||
|
||||
Anyone? |
|
#7
|
||||
|
||||
|
What does the operator !~ mean anyhow? I changed it to != because the code wants to know if it doesn't equal /orderid/ then to go to the nocookie page.
|
|
#8
|
|||
|
|||
|
!~ means 'does not contain'.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Checking for Cookie Code |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|