0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Mubashar Abbas
  • 5,536
  • 4
  • 38
  • 49
  • Check this one, maybe it fits your issue: http://stackoverflow.com/questions/612034/how-can-i-set-a-cookie-and-then-redirect-in-php – lesssugar Nov 27 '14 at 20:36
  • Possible duplicate of [How can I set a cookie and then redirect in PHP?](https://stackoverflow.com/questions/612034/how-can-i-set-a-cookie-and-then-redirect-in-php) – halfer Oct 29 '17 at 12:03

0 Answers0