Okay, so I'm working on a little project, and I've got a little loginbox, it has a checkbox, just like vbulletin, to keep you logged in(set a cookie) or just use a $_SESSION...
So here's how my login script looks:
<?php
// Log in
$loginname = isset($_POST['usname']) ? $_POST['usname'] : "";
$loginpass = isset($_POST['passw']) ? $_POST['passw'] : "";
$loginpass = md5($loginpass);
$remember = isset($_POST['remember']);
if(!empty($loginname) && !empty($loginpass)) {
$c = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE name = '$loginname' AND password = '$loginpass'"));
if($c > 0) {
if($remember == TRUE) {
setcookie("usname", $loginname, time()+(7*86400));
setcookie("pass", $loginpass, time()+(7*86400));
} else {
$_SESSION['loggedin'] = $loginname;
}
}
}
header("Location: /play/game/");
?>
Now, I soon noticed that i wasn't logging in when using cookies (session works fine), so I decided to echo the cookies in my index.php
// Log in check:
if(isset($_SESSION['loggedin']) || isset($_COOKIE['usname'])) {
... //i've tried combinations of isset and !empty, no difference
}
// testing if they are set in index.php
echo 'usname: '.@$_COOKIE['usname'].'<br />';
echo 'pass: '.@$_COOKIE['pass'].'<br />';
echo 'session: '.@$_SESSION['loggedin'].'<br />';
and the cookies all return zip... So i thought there must be something wrong with the way i'm setting these cookies... However, when i had a look at my cookies (with mozilla firefox) i soon saw that they were perfectly set... I've got a cookie usname, with the username, and a cookie pass, but the website doesn't recognize them for some reason... other way around, when I log out
<?php
// Logout
setcookie("usname","");
setcookie("pass","");
session_destroy();
header("Location: /read/home/");
?>
the cookies stay, right were they are...
I haven't got a clue what's going on... I first thought it had something to do with the way I included my login page, but I've tried different things and none work...