On Tue, March 25, 2008 8:11 pm, Mark Weaver wrote: > 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); Because IE engineers CANNOT READ a technical document to save their lives, you MUST supply a "path" if you supply a "time": setcookie("cookiename", $values, time() + $timevalue, "/"); You also don't tell use what $timevalue is, so that could be something very wrong... :-) > Inside the Cookie > ========================== > Content: blah%7Cblah%7Cblah > > > Getting info Out Of Cookie > ========================== > list($first,$second,$third) = explode("|", $values); Unless you have register_globals set to "ON" (bad!) then $values will only have meaning in the setcookie script... > 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"; You should NOT NOT NOT NOT NOT be storing a username *or* password in a cookie!!! > } > 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. What *is* in your cookies? var_dump($_COOKIES); Perhaps putting '|' in there is not a valid character? You could base64 encode it or ... > 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. :) It would be some chunk of the Netscape Cookie spec. Google for "Netscape Cookie spec" and read that. It's only a page. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php