I followd a tutorial on the internet for a php inlog whit session but i want to add cookies to it only im struggling getting mine query items into the cookies
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND
password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$secondQuery = "SELECT * FROM users WHERE userid='$emptyUserid'
AND hash='$emptyHash'";
$result = mysqli_query($db,$secondQuery);
$row = mysqli_fetch_row($result);
$emptyUserid = $row['userid'];
$emptyHash = $row['hash'];
setcookie("userid","$emptyUserid",time()+ (3600 * 24 * 7));
setcookie("hash","$emptyHash",time()+ (3600 * 24 * 7));
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}
im struggling whit the second query the other one works fine i need the cookies to later check on the webpage if the user closed there page if gis cookies matches the data base so i can remake his session whit out him having to relog in (its for school project im kinda new to php)
the issue is when i var dump or echo the cookies they are empty no matter what