0

Hi All,

I've this problem with cookies. I am lost as I can't understand why this code does not work as expected.

Please help!!

$rq =$_REQUEST['r']  ;
$value = $_REQUEST['v'];
setcookie("XYZ",$value, time()+60*60*24*30) ;
echo "Value is ".$value; 
if ($rq =='showdata'){
    print_r($_COOKIE);
    echo "Cookie is".$_COOKIE['XYZ'];
    exit;
}

Output: when passing values r=showdata&v=test and pressing F5 repeatedly.

Value is testArray
(
[XYZ] =>
[PHPSESSID] => 060ee31ae35b8fb1262d0660bd925746
)
Cookie is

Edited by jsrpatna: n/a

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by diafol
0

USe $_GET instead of $_REQUEST

You can't show the cookie on the same page as when you set it. You need another call to the server for this. However, I think it should show on second load.
//edit

Yes tried it and it loaded on second load, giving an error first time around.

Search the cookies in the browser to see if it's stored where you think. The path could be wrong.

Edited by diafol: n/a

0

Thanks Ardav for your response.

You'll notice that the array output in the browser does show the cookie name. However, it doesn't show the value that was set.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.