Cookie Trouble: getting the information back out...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I suspect I already know part of the answer to this, but I'm not sure which way to go with it. I've got a project I'm working on and one of the things it's got to do is set cookies and then read them later. When the app was first written I was doing everything in PERL and cookies are fairly straight-forward, however I'm finding cookies in PHP somewhat problematic.

Setting the cookie is a snap, however getting the info back out is, well... problematic.

this is basically what I'm doing, what I'm seeing in the cookie, and what I'm getting back out.

Setting the cookie
==========================
$values = "blah|blah|blah";
setcookie("cookiename", $values, time()+$timevalue);


Inside the Cookie
==========================
Content: blah%7Cblah%7Cblah


Getting info Out Of Cookie
==========================
list($first,$second,$third) = explode("|", $values);


Cookie Test Page
==========================
if (isset($_COOKIE["cookiename"])){
	list($first,$second,$third) = explode('|',$_COOKIE["cookiename"]);
	echo "<p>I found your cookie</p>\n";
	echo "<p>The following Values were Contained in the cookie:<BR>
	      Username: $first<BR>
	      Password: $second<BR>
	      Type    : $third</p>\n";
}
else{
	echo "<p>I wasn't able to find your cookie.</p>\n";
}

Now, I've constructed a cookie_test.php page to check things out and the strange behavior I'm seeing is, upon first execution I get the "else" block, but if I hit the browser's reload button I get the "if" block. At first I thought the cookie wasn't being read at all because of weird characters, but then upon reloading the page and seeing the "if" block being displayed I'm thoroughly confused. It's gotta something simple I'm missing.

and I swear if someone tells me to RTFM I'm gonna shit and go blind cause I haven't got a clue as to "which" part of the FM to read concerning this. :)

thanks,

--
Mark
-------------------------
the rule of law is good, however the rule of tyrants just plain sucks!
Real Tax Reform begins with getting rid of the IRS.
==============================================
Powered by CentOS5 (RHEL5)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux