CodeIgniter Cookie won't set but Session is working?

前端 未结 3 1951
暖寄归人
暖寄归人 2021-01-24 18:56

I\'m working with CodeIgniter to set up some user login functions to my site using Twitter and Facebook, this parts working and the session works fine.

When I try to set

3条回答
  •  天命终不由人
    2021-01-24 19:25

    The problem is probably within your domain variable BASE_URL, which isn't a part of CI constants, probably doesn't contain what you expect or what a cookie initialization requires.

    Try doing it like this:

    //Setup a guid
    $guid = uniqid();
    
    //Setup a random cookie and point it to db user
    $cookie = array(
      'name'   => 'TheCookieName',
      'value'  => $guid,
      'expire' => 86500, // have a high cookie time till you make sure you actually set the cookie
      'domain' => '.example.org', // the first . to make sure subdomains isn't a problem
      'path' => '/',
      'secure' => TRUE
    );
    
        set_cookie($cookie);
    

    Remember that cookies will never be available until a new request have been made.
    Redirect to another page on the domain specified in the cookie setup and check for the cookie again.

提交回复
热议问题