Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy Cookie Question... 1

Status
Not open for further replies.

kizmar2

Programmer
May 25, 2004
164
US
Assuming there's a cookie set and it has a value, how do I pull the value of the cookie into a variable?

KizMar
------------
 
Here's my problem: I have a CGI script that's creating a cookie (and the cookie is actually there with a value in it). Later I'm trying to read the cookie info and it's pulling blanks...

here's the line of code that's pulling the cookie info:

Code:
my ($t) = $ENV{'HTTP_COOKIE'} =~ /t=(\d+)/;

We can assume that there is a cookie named "t". I've checked, it's there and it has a value in it.

This is someone else's code and I know very little about Perl. Can anyone help?

KizMar
------------
 

this is what i use to set and read a cookie...


Code:
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);


## Make a CGI object
my $q = new CGI;


### gets the value of the cookie named username into
### the var $cookie_username_get
my $cookie_username_get = $q->cookie('username');


### sets the cookie $cookie_username_set
### to the value of $the_username
my $cookie_username_set = $q->cookie (
               -name    => 'username',
               -value   => "$the_username",
               -path    => '/',
               -expires => '+1y'
               );

I'm new to PERL myself, so i might not be explaining it in detail, if not please let me know and I'll try again. :)
hope this helps


 
I finally got this method to work. I must have missed something the first time I did this.

Thanks for your post!

KizMar
------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top