Gossamer Forum
Home : General : Perl Programming :

Cookies: Help please

Quote Reply
Cookies: Help please
Hi Folks

I'm creating an intranet, and for once in my life I have decided to save every user's username and password in a cookie instead of passing argument to every script. However, I am running into problems.

This is a breakdown of my site, so far...

1. I have created a page for people to enter their login name and password.

2. Once they submit the details on the page above, they are taken to a login script which authorizes the user, and if authorization is correct, create a cookie of that user and password and then redirect to the main script.

3. main script, which should in theory grab the username and password from the cookie saved into the browser at the previous step.

My problem? It doesn't seem to want to save the cookie to my browser and/or I am retrieving it incorrectly.

This is the code I use to save my cookie into the user's browser:

$cookie_user = $query->cookie(-name=>'login',
-value=>"$A::login");
$cookie_pass = $query->cookie(-name=>'pass',
-value=>"$A::pass");

print $query->header(-cookie=>[$cookie_user,$cookie_pass]);


and this is the code I use to retireve my cookies in the main script:

$user_login = $query->cookie('login');
$user_pass = $query->cookie('pass');


Can anyone spot anything wrong with my code? Is there another, proven way to do this?

Any help would be appreciated.

Thank you
Wil Stephens

Quote Reply
Re: Cookies: Help please In reply to
Looks to me like you are missing a few of the $cookie attributes (like domain) to save the cookie properly.

Here is an example of cookie codes I use in LINKS SQL:

Code:

$user_cookie = $in->cookie (
-name => 'Username',
-value => $user,
-expires => '+1y',
-path => '/',
-domain => '.domain.com'
);


Without identifying the domain, I don't think you will be able to set the cookie.

Hope this helps.

Regards,

Eliot Lee
Quote Reply
Re: Cookies: Help please In reply to
Thank you. I will give your suggestions a shot.

Rgds
Wil Stephens

Quote Reply
Re: Cookies: Help please In reply to
Eliot

Finally got round to implementing your suggestions. Specifying the domain name or the IP address of the machine the cookie should work with worked a treat.

Thank you.

- w

Quote Reply
Re: Cookies: Help please In reply to
You're welcome.

Regards,

Eliot Lee Wink
http://anthrotech.com/