I stuck this code at the top of my login page which should redirect the user back to the home page if they are already logged in, but it doesn't work, it simply does nothing, even though I know the cookies has been set. To be extra sure the cookie had been set I went into chrome settings and checked all the cookies that my website has stored and sure enough, my cookie was set there. I have no idea why this isn't working, it's probably just a silly little error I made, but I've been programming all night, and I figure a fresh set of eyes might spot something I might have missed.
Code:
<?php
if(isset($_COOKIE['user'])){
header("Location: index.php?content=home");
}
?>
How the cookie is assigned:
<?php
$user = $_POST['user'];
$pass = $_POST['pass'];
$redir = $_GET['redir'];
include('con.php');
$query = mysql_query("SELECT * FROM users WHERE name='{$user}'");
$numrows = mysql_num_rows($query);
$array = mysql_fetch_array($query);
if($user==""||$pass==""){
header('Location: ../login.php?error=Please fill out EVERYTHING&redir=' . $redir);
}
else if($numrows < 1){
header('Location: ../login.php?error=User does not exist&redir=' . $redir);
}
else if($pass !=$array['pass']){
header('Location: ../login.php?error=Invalid user/pass combo&redir=' . $redir);
}
else{
setcookie("user", $array['ID']);
header('Location: ../index.php?content=' . $redir);
}
?>
EDIT: Below is what i am getting when i print_r($_COOKIE)
Array
(
[_okbk] => cd4=true,vi5=0,vi4=1381557924453,vi3=active,vi2=false,vi1=false,cd8=chat,cd6=0,cd5=away,cd3=false,cd2=0,cd1=0,
[_ok] => 5197-288-10-3215
[olfsk] => olfsk8855679365806282
[wcsid] => aqVZBde4DlLmegpG5L3JS16nDXl0aIA9
[hblid] => oBSPj2E8hdamA4nK5L3JS16nDXrqAaPK
[_oklv] => 1381563654520,aqVZBde4DlLmegpG5L3JS16nDXl0aIA9
)