crescue
asked on
How can I read the value from a cookie previously set using php
How can I read the value from a cookie previously set using php. I have set the cookie using :
<?php
$fromUser = htmlspecialchars($_GET["un ame"]);
$cookie_name = "user";
$cookie_value = $fromUser;
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
Now I want to read the value of that cookie when I goto a different page, within the same domain.
Tnx for your help
<?php
$fromUser = htmlspecialchars($_GET["un
$cookie_name = "user";
$cookie_value = $fromUser;
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
Now I want to read the value of that cookie when I goto a different page, within the same domain.
Tnx for your help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tnx it worked and I learned something new
// get the user:
$name = $_COOKIE['user'];
You might want to check it exists before using it by using the isset() function:
$name = isset($_COOKIE['name']) ? $_COOKIE['name'] : null;