I'm trying to make a basic password protection scheme using cookies however when I try to set the cookie I am unable to using this code:
if($_COOKIE['RGUsername'] == NULL) {
$query = "SELECT user, pass FROM login ";
$query .= "WHERE user= '$Username' AND pass = '$Password'";
$result = mysql_query($query);
if(mysql_num_rows($result)) {
echo("Logged in");
$query = "UPDATE from login SET logged = SYSDATE()";
$query .= "WHERE user = '$Username' AND pass = '$Password'";
mysql_query($query);
if(!isset($_COOKIE['RGUsername'])) {
setcookie ("RGUsername", $Username, time() + 3600);
}
} else {
echo("Incorrect Login redirecting back to main page");
}
The code i'm using to check if the cookie is registered is:
if(!isset($_COOKIE['RGUsername'])) {
include("mini_login.html");
} else {
echo("Logged In as ");
echo($_COOKIE['RGUsername']);
}