Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 19th, 2001, 12:28 PM
jackmack's Avatar
jackmack jackmack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Hingham, MA
Posts: 18 jackmack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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";

Reply With Quote
  #2  
Old June 19th, 2001, 01:35 PM
GabePreston GabePreston is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: York, PA
Posts: 0 GabePreston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to GabePreston Send a message via AIM to GabePreston Send a message via Yahoo to GabePreston
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.

Reply With Quote
  #3  
Old June 19th, 2001, 01:59 PM
jackmack's Avatar
jackmack jackmack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Hingham, MA
Posts: 18 jackmack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #4  
Old June 19th, 2001, 04:20 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
Thumbs up

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:
Originally posted by jackmack
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?
__________________

Thunder Rain Internet Publishing

Custom Programming & Database development
Providing Personal/Business
Internet Solutions that work!

Reply With Quote
  #5  
Old June 19th, 2001, 09:50 PM
jackmack's Avatar
jackmack jackmack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Hingham, MA
Posts: 18 jackmack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old June 22nd, 2001, 10:19 PM
jackmack's Avatar
jackmack jackmack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Hingham, MA
Posts: 18 jackmack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Anyone?

Reply With Quote
  #7  
Old June 22nd, 2001, 10:37 PM
jackmack's Avatar
jackmack jackmack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Hingham, MA
Posts: 18 jackmack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #8  
Old June 23rd, 2001, 12:04 AM
SeltaR SeltaR is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 SeltaR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
!~ means 'does not contain'.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Checking for Cookie Code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT