CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Cookie creation failing in perl

 



trayip
Novice

May 10, 2005, 11:17 AM

Post #1 of 9 (2434 views)
Cookie creation failing in perl Can't Post

Hello,

I created a cookie in the cookie jar and attached it to the useragent. Then, when I try and access the server computer where the cookie is supposed to register, it doesn't seem to work.

The server needs the cookie to see what username is currently logged in, so the perl code is supposed to make a cookie with certain settings (using set-cookie I believe), and then do a GET at a certain site (with a QUERY_STRING which gets parsed).

Why won't it work?

Matt


KevinR
Veteran


May 10, 2005, 12:32 PM

Post #2 of 9 (2430 views)
Re: [trayip] Cookie creation failing in perl [In reply to] Can't Post

Post the relevant code and maybe someone can see if there is a problem in the perl code.
-------------------------------------------------


trayip
Novice

May 10, 2005, 12:37 PM

Post #3 of 9 (2429 views)
Re: [trayip] Cookie creation failing in perl [In reply to] Can't Post

Alright. This is my code. I hope someone can help...

# Create a cookie jar and make a cookie with the correct values
use LWP::UserAgent;
use LWP::Simple;
use HTTP::Cookies;
use HTTP::Request;

$ua = LWP::UserAgent->new;
$ua->agent("Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt");

$cookie_file = "cookies.txt";
$ua->cookie_jar(HTTP::Cookies->new( 'file' => $cookie_file, 'autosave' => 1, 'ignore_discard' => 1));
$ua->cookie_jar->set_cookie(
0, # version
"test", # key
"id=$name", # value
'/sbbrr', # path
'gifu', # domain
'8080', # port
false, # path_spec -- BOOLEAN VALUE
false, # secure -- BOOLEAN VALUE
(time + 3600), # max age
false, # discard -- BOOLEAN VALUE
{} # misc
);

# Make the vote using a GET
$url = URI->new( $URL );
$url->query_form(
'sid' => $service_id,
'itemId' => $random_item,
'value' => $random_rating,
);
$res = $ua->get($url);


KevinR
Veteran


May 10, 2005, 10:07 PM

Post #4 of 9 (2416 views)
Re: [trayip] Cookie creation failing in perl [In reply to] Can't Post

have you tried quoting the words false:

'false', # path_spec -- BOOLEAN VALUE
'false', # secure -- BOOLEAN VALUE
(time + 3600), # max age
'false', # discard -- BOOLEAN VALUE
-------------------------------------------------


trayip
Novice

May 11, 2005, 7:21 AM

Post #5 of 9 (2409 views)
Re: [KevinR] Cookie creation failing in perl [In reply to] Can't Post

Yea I did that, but it still doesn't seem to work. The cookie isn't getting transfered to the java servlet which is supposed to interpret the cookie, read in its value, and set the username to whatever is after the 'id=' (the $name value).

Any other ideas? This is really bugging me...


davorg
Thaumaturge / Moderator

May 11, 2005, 9:29 AM

Post #6 of 9 (2404 views)
Re: [trayip] Cookie creation failing in perl [In reply to] Can't Post

By putting the string "false" there, you're actually having the opposite effect to the one you want. The string "false" will be interpreted as a true value in Perl. You actually want to use a false value (0, '0', an empty string, or undef).

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


trayip
Novice

May 11, 2005, 10:20 AM

Post #7 of 9 (2400 views)
Re: [davorg] Cookie creation failing in perl [In reply to] Can't Post

Well then, what should I put as the value? I want those boolean values to be false, so what do I need? Should I do 0 or undef or what? I want it to return false...

Thanks,
Matt


KevinR
Veteran


May 11, 2005, 12:57 PM

Post #8 of 9 (2395 views)
Re: [trayip] Cookie creation failing in perl [In reply to] Can't Post

try the values davorg suggested
-------------------------------------------------


trayip
Novice

May 13, 2005, 11:19 AM

Post #9 of 9 (2387 views)
Re: [KevinR] Cookie creation failing in perl [In reply to] Can't Post

Damn still didn't work....maybe someone can point me to a website or another forum or hopefully another thread that had the same problem and hopefully a solution? lol I'm doing a client-side perl script rather than server-side, and every website i've googled has been server-side...doh :(

Matt

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives