Cookie troubles
Posted: Sat Dec 11, 2004 7:56 am
To set the cookie:
[code]<?PHP
function _setCookie($aArgs) {
$uInfo = implode("|", $aArgs);
setcookie("ccAccount", $uInfo, time()+31536000, "/", ".codecrypt.org", "0");
}
if ($_GET['id'] and $_GET['user'] and $_GET['rank']) {
$uInfo = array($_GET['id'], $_GET['user'], $_GET['rank']);
_setCookie($uInfo);
echo "<meta http-equiv=\"refresh\" content=\"0;URL='http://codecrypt.org/members.php'\" />";
}
else {
echo "You cannot access this file directly";
}
?>[/code]
To unset the cookie:
[code]<?PHP
setcookie("ccAccount", null, time()-1, "/", "", "");
unset($_COOKIE["ccAccount"]);
echo "<meta http-equiv=\"refresh\" content=\"0;URL='http://codecrypt.org/index.php'\" />";
?>[/code]
It sets the cookie fine, but when I try and log out, it won't.
This is the code to check if its logged in:
[code]if ($uInfo = $users->getSession()) {
echo "Thankyou for logging in ". $uInfo['Username'];
echo "<br /><a href=\"members.php?action=logout\">Click here to log out</a>";
}[/code]
[code]function getSession() {
if (isset($_COOKIE['ccAccount'])) {
$uInfo = explode("|", $_COOKIE['ccAccount']);
$return['uID'] = $uInfo['0'];
$return['Username'] = $uInfo['1'];
$reutrn['Rank'] = $uInfo['2'];
return $return;
}
else {
return false;
}
}[/code]
[code]<?PHP
function _setCookie($aArgs) {
$uInfo = implode("|", $aArgs);
setcookie("ccAccount", $uInfo, time()+31536000, "/", ".codecrypt.org", "0");
}
if ($_GET['id'] and $_GET['user'] and $_GET['rank']) {
$uInfo = array($_GET['id'], $_GET['user'], $_GET['rank']);
_setCookie($uInfo);
echo "<meta http-equiv=\"refresh\" content=\"0;URL='http://codecrypt.org/members.php'\" />";
}
else {
echo "You cannot access this file directly";
}
?>[/code]
To unset the cookie:
[code]<?PHP
setcookie("ccAccount", null, time()-1, "/", "", "");
unset($_COOKIE["ccAccount"]);
echo "<meta http-equiv=\"refresh\" content=\"0;URL='http://codecrypt.org/index.php'\" />";
?>[/code]
It sets the cookie fine, but when I try and log out, it won't.
This is the code to check if its logged in:
[code]if ($uInfo = $users->getSession()) {
echo "Thankyou for logging in ". $uInfo['Username'];
echo "<br /><a href=\"members.php?action=logout\">Click here to log out</a>";
}[/code]
[code]function getSession() {
if (isset($_COOKIE['ccAccount'])) {
$uInfo = explode("|", $_COOKIE['ccAccount']);
$return['uID'] = $uInfo['0'];
$return['Username'] = $uInfo['1'];
$reutrn['Rank'] = $uInfo['2'];
return $return;
}
else {
return false;
}
}[/code]