I am building a website with logins. I have sessions working fine but I need to be able to keep them logged in if the click remember me. Currently I have the login script saving a cookie with the Username and Password they type to some cookies. I the below script $username and $password are set higher in the script. The $_SESSION variables are getting set fine. And I know the script is going into the if statement because before I place a alert box in there.
login.php
while($row = mysql_fetch_array($getLoginResults))
{
$error = "Login Successful";
$_SESSION['Username'] = $_POST['username'];
$_SESSION['Password'] = $_POST['password'];
if($keep == 1)
{
setcookie("Username", $username, time()+3600*24*30);
setcookie("Password", $password, time()+3600*24*30);
}
}
When I check the login, I have a javascript alert so I knoe the cookie is set but the alert box is coming up empty.
check_login.php
echo "<script>alert('".$_COOKIE['Username']."')</script>";
What am I missing???
Try using setcookie with a a path specified, this used to catch me out, as it assumes the current path by default. Using / will make the cookie work for the whole domain