I've created a page that sets a cookie on the click of a button(ajax with PHP) and then redirects to a different page (JavaScript).
$.ajax({
url: "addTeacher.php",
dataType: 'html',
data: text,
cache: false,
type: "GET",
success: function(html) {
window.location = "teacherList.php";
}
});
But when I try to access the set cookie in the page that is being redirected to(teacherList.php) it is empty. If refresh the redirected page once more, then the cookie is accessible.
This is how I set the cookie in addTeacher.php.
addTeacher($teacher, $items);
setcookie("$teacher_id", "$teacher_id", time() + (86400 * 1), "/");