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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't fetch cookie from a different directory

Status
Not open for further replies.

manjoufna

Programmer
Sep 7, 2001
9
0
0
US
I have a set of Perl scripts in one directory (let call Directory 1: /htdocs/menu/perl/) that set and fetch a cookie via CGI::Cookie. One of these scripts calls another script in a different directory (let's call Directory 2: /htdocs/maint/) that is unable to fetch the same cookie.

Here is how I set the cookie (in script A.pl in Directory 1) :

use CGI;
use CGI::Cookie;
my ($http) = new CGI;
$login_id = 'testid';
my $icookie = $http->cookie(
-name=>'cookie_id',
-value=>$login_id,
-expires=>'',
-path=>''
-domain=>'',
-secure=>0
);

Subsequent script (B.pl) sends the cookie with:

print $http->header(-cookie=>$icookie);


Then another script in Directory 1(C.pl) successfully fetches the cookie via a central fetch subroutine in fetch.pl:

use CGI;
use CGI::Cookie;
$http = new CGI;
my %cookies = CGI::Cookie->fetch;
$cookie_name = $http->cookie('cookie_id')

This works fine. $cookie_name and %cookies each exist.

Now, I have another script (let's call it Y.pl in Directory 2). C.pl from Directory 1 calls Y.pl in Directory 2, which calls the central fetch code in fetch.pl but nothing comes into %cookies.

I had to use cookies because the user does not want these values to be passed in the URL when calling programs.

fetch.pl is in Directory 2.

I tried playing with the domain and path of the initiate cookie statement, but the results were the same.

The cookie does not expire because the process continues to another script (in Directory 1) which fetches the cookie successfully.

It seems to be that scripts in Directory 1 can fetch the cookies, but scripts in directory 2 cannot. And these scripts use the same sub routine.

Has this problem ever happened to anyone else before?

Thanks,
Margaret
 
Sometimes cookies dont act the way you would expect. You may try implicitly setting the path and he domain.
my $icookie = $http->cookie(
-name=>'cookie_id',
-value=>$login_id,
-expires=>'',
-path=>'./htdocs/'
-domain=>'.yourdomain.com',
-secure=>0
);
haunter@battlestrata.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top