I have set my cookies as an array so that all the info is stored in 1 cookie.
<?php setcookie("ptdetails[user]", "$user", time()+60*60*24*30, "/");
setcookie("ptdetails[pword]", "$pword", time()+60*60*24*30, "/");
setcookie("ptdetails[usertype]", "$usertype", time()+60*60*24*30, "/");
setcookie("ptdetails[secure]", "$secure", time()+60*60*24*30, "/");
setcookie("ptdetails[pagestyle]", "$pagestyle", time()+60*60*24*30, "/");
header('Location: index.php') ?>
Now I am trying to get the information out of the cookies and so far having no luck.
if(!isset($user) OR !isset($pword) OR !isset($usertype) OR !isset($secure) OR !isset($pagestyle)) {
print_r($_COOKIE);
echo("<hr />");
foreach ($_COOKIE['ptdetails'] as $name => $value) {
echo "$name : $value <br />\n";
$value = $ptinfo[$name];;
}
echo("<hr />");
print_r($ptinfo);
}
I've looked through the php documentation on both cookies and arrays but I cannot find the answer to the problem I'm having. Anyone's help would be appreciated.
By the way. When I tested it using the print_r($_COOKIE); and the echo "$name : $value <br />\n"; I got the following:
Array ( [ptdetails] => Array ( [user] => Josh [pword] => something [usertype] => admin [secure] => true [pagestyle] => default ) )
user : Josh
pword : something
usertype : admin
secure : true
pagestyle : default
Code:
<?php setcookie("ptdetails[user]", "$user", time()+60*60*24*30, "/");
setcookie("ptdetails[pword]", "$pword", time()+60*60*24*30, "/");
setcookie("ptdetails[usertype]", "$usertype", time()+60*60*24*30, "/");
setcookie("ptdetails[secure]", "$secure", time()+60*60*24*30, "/");
setcookie("ptdetails[pagestyle]", "$pagestyle", time()+60*60*24*30, "/");
header('Location: index.php') ?>
Now I am trying to get the information out of the cookies and so far having no luck.
Code:
if(!isset($user) OR !isset($pword) OR !isset($usertype) OR !isset($secure) OR !isset($pagestyle)) {
print_r($_COOKIE);
echo("<hr />");
foreach ($_COOKIE['ptdetails'] as $name => $value) {
echo "$name : $value <br />\n";
$value = $ptinfo[$name];;
}
echo("<hr />");
print_r($ptinfo);
}
I've looked through the php documentation on both cookies and arrays but I cannot find the answer to the problem I'm having. Anyone's help would be appreciated.
By the way. When I tested it using the print_r($_COOKIE); and the echo "$name : $value <br />\n"; I got the following:
Quote:
Array ( [ptdetails] => Array ( [user] => Josh [pword] => something [usertype] => admin [secure] => true [pagestyle] => default ) )
user : Josh
pword : something
usertype : admin
secure : true
pagestyle : default