Jump to content

[SOLVED] Cookies being read


gerkintrigg

Recommended Posts

Hi all.

 

I'm writing a cookie with the following code:

setcookie("mem", "yes", time()+7200,"/shop/","allpet.co.uk");

And I'm reading it from another page with:

$ul_mem = $HTTP_COOKIE_VARS["mem"];

but the second page does not recognise it. Is there soemthing I'm doing wrong?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/42105-solved-cookies-being-read/
Share on other sites

HTTP_COOKIE_VARS is depreciated. Use $_COOKIE instead.

 

This go for all the other HTTP_*_VARS variables. Example:

 

$HTTP_POST_VARS should be $_POST

$HTTP_GET_VARS should be $_GET

 

ALso note that you cannot use and set cookies that where set on the same page. You will have to refresh the page in order for the cookie that you just set to come available. However if you are setting and using cookies on seperate pages then you dont need to refresh.

try this

 

setcookie("mem", "yes", time()+7200,"/shop","/");

OR

setcookie("mem", "yes", time()+7200,"/shop","allpet.co.uk");

 

If that does not work, read up on cookies here:

 

http://us3.php.net/manual/en/function.setcookie.php

 

It explains about the domains and paths etc. If this is running on Localhost, you need to set the domain part to false, remember that.

 

--FrosT

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.