Reputation: 73
Let's say the user logs in, a cookie is sent and the user is redirected to another page.
How do I make it where I can convert the cookie value into a variable in PHP (on the page they are redirected to)?
I want to write the cookie value to a .txt file.
Thanks.
Upvotes: 0
Views: 726
Reputation: 79
Cookies stored in the $_COOKIE
array. So if you want to use it, just assign an appropriate cookie key value to your variable, for example:
$name = $_COOKIE['name'];
Upvotes: 1
Reputation: 4676
Cookie is available in $_COOKIE
as $_COOKIE['key']
; get that value and store it in a variable, which can be output to a file.
Upvotes: 0
Reputation: 1917
You don't need to convert them just retrieve into a php variable.
<?php
if(isset($_COOKIE['lastVisit']))
$visit = $_COOKIE['lastVisit'];
else
echo "You've got some stale cookies!";
echo "Your last visit was - ". $visit;
?>
see here tutorial
Upvotes: 3
Reputation: 145512
Well cookies live in the $_COOKIE
global. (When received.)
And writing them to a file would be as boring as:
file_put_contents("var/cookie.txt", $_COOKIE["cookiename"]);
Upvotes: 3
Reputation: 799450
From the docs:
Any cookies sent to you from the client will automatically be included into a
$_COOKIE
auto-global array ifvariables_order
contains "C".
Upvotes: 5