I am working on this CodeIgniter project, and I want to provide the 'Remember Me' feature for logging in. and for that I am setting a cookie like this.
if(strtolower($loggedin) == 'on') {
//set cookie for 30 days.
setcookie('teacher_login', $teacher_id, time()+60*60*24*30);
}
redirect();
I have checked by using,
echo setcookie('teacher_login', $teacher_id, time()+60*60*24*30);
and the output was '1'. But after the redirect to the home controller, there when I check use the following:
if (isset($_COOKIE["teacher_login"])) {
echo $_COOKIE["teacher_login"];
} else {
echo 'cookie not set';
}
and the output here is 'cookie not set'.
I don't know what is going on here, I checked the PHP manual and the instructions seemed simple enough. Moreover I tried to use the CodeIgniter cookie helper. set_cookie($cookie)
didn't work either.
What could possibly be the problem?