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

Cookies

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am attempting to place 4 cookies on the hard drive of users that access my script, and am using the following code :
print "Set-Cookie: CoordC=$FormData{'Login_CoordC'}; expires=Mon, 6-Feb-2045 00:00:00 GMT; domain=trt.tibsun.com\n";
print "Set-Cookie: CoordG=$FormData{'Login_CoordG'}; expires=Mon, 6-Feb-2045 00:00:00 GMT; domain=trt.tibsun.com\n";
print "Set-Cookie: CoordP=$FormData{'Login_CoordP'}; expires=Mon, 6-Feb-2045 00:00:00 GMT; domain=trt.tibsun.com\n";
print "Set-Cookie: Password=$FormData{'Login_Password'}; expires=Mon, 6-Feb-2045 00:00:00 GMT; domain=trt.tibsun.com\n";

Each of the variables stands for something so dont worry about that. However I have some questions :

1) Internet Explorer 5.0 is making them all into one file in my C:\WINDOWS\Cookies directory. Should it be doing this?
2) It wont work. I can access the "CoordC" variables, but all of the other ones are not working, and I can not access them from the script that needs to access the information in these cookies.

Please help.
 
This is my new nickname (registered), but, I made the scripts into .txt's so you can view them and see what is wrong :

- This file is the login script that sets the cookies
- This is the file that is supposed to display $Crumbs{'Password'} but for some reason no scripts will recognize these, but will only recognize the value of the first cookie, $Crumbs{'CoordC'}, and not the other 3
- This file contains subroutines and paths (in scalar form) etc. It contains the subroutine (VerifyCookie) that is supposed to parse the $ENV{'HTTP_COOKIE'} variable

PLEASE look at these and tell me what is wrong.

- Ben Russell
- President of Intracor Technologies (
 
I'm not really sure why this isn't working, but can you combine all the cookies into one? I know that's treating the symptom rather than the problem, but until someone who knows the answer responds it ought to get you around it.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Don't send more than one variable, concatentate all the variable values together using join and then use that value for the cookie. When you get the value back from the cookie just use split to deconcatenate (is that a word?) the original variable values. Again, it's not a perfect solution, but it should work.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I dont quite understand d what you mean. Like say the first variables value is "first" second variable value is "second" and so on for all 4 variables. How would I put them into one cookie and then split it? - Ben Russell
- President of Intracor Technologies (
 
to join them:[tt]
$joined = join("|", qw{first second third forth});[/tt]

then pass that as the cookie variable.
to split them back apart:[tt]
($first, $second, $third, $forth) = split("|", $joined);[/tt]

then $first will equal 'first', etc. "|" can be any character you want, provided that character won't be in any of the values to be set. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Thanks stillflame, that's exactly what I meant! Sorry I wasn't more specific BenRussell, I assumed you knew those perl functions. :~/

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
And then would I just put to set the cookie :
print "Set-Cookie : Information=$joined";
? (Yes I realize I need to put the other info too). - Ben Russell
- President of Intracor Technologies (
 
correct :) "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
OK, I have done that. However, the "first, second, third, fourth" must be scalars, and when I am making them scalars, on the cookie instead of displaying the scalar's value, it is displaying the ACTUAL scalar. How should I fix this? - Ben Russell
- President of Intracor Technologies (
 
post the part of the code that you're doing this in. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Well, I figured out that after all, now I am having the problem of it not recognizing the $Crumbs{'Information'} scalar which contains all the info. I am using the following code to parse the cookies, please tell me if something is wrong :

if ($ENV{'HTTP_COOKIE'}) {
@Cookies = split (/;/, $ENV{'HTTP_COOKIE'});
foreach $Cookie (@Cookies) {
($name, $value) = split (/=/, $Cookie);
$Crumbs{$name} = $value;
}
}

- Ben Russell
- President of Intracor Technologies (
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top