Forum Moderators: coopster

Message Too Old, No Replies

Fetching Cookie Information

Won't work in index.php?d=directory&p=page. Cookie path?

         

Will Hamilton

1:10 am on Feb 17, 2007 (gmt 0)

10+ Year Member



I'm trying to read a cookie through php with a simple..

<?php 
$variable = $HTTP_COOKIE_VARS["cookie"];
?>

..and manage to do it okay. However, I can only do so when viewing the file directly - that is to say, in the format /directory/page.php. My site uses /index.php?d=directory&p=page and the cookie info I've pulled down simply won't display / isn't there when viewing it like this.

I imagine it's something to do with the cookie's path - it's assigned from within a sub-directory, but given the path /, so it can be accessed across the site. Is there anything obvious I'm doing wrong? Any reason for the cookie not to be accessed when doing a php?d=.. etc? Thanks.

eelixduppy

3:26 pm on Feb 18, 2007 (gmt 0)



Hello,

If you are truly doing what you are saying, then you are experiencing strange behavior.

Have you tried different browsers to see if the problem is browser-specific?

From the manual:


Note: Microsoft Internet Explorer 4 with Service Pack 1 applied does not correctly deal with cookies that have their path parameter set

Maybe? :)

The concept is correct, so either you have an error in your code, or something else isn't right here.

And unless you are using an older version of PHP, you should use the following, although what you have is still supported:


$variable = $_COOKIE["cookie"];

cmarshall

7:56 pm on Feb 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have no idea if this [webmasterworld.com] will help. Jatar was able to help me out with a really odd cookie problem.

I recommend the Web Developer Toolbar, by Chris Pederick, and Firefox. It makes checking cookies darn easy.

majjk

11:10 pm on Feb 26, 2007 (gmt 0)

10+ Year Member



I'm having exactly the same problem. Did you manage to figure out what the problem was?