PHP Cookies works well on localhost, but it's not working on live server

后端 未结 6 1214
死守一世寂寞
死守一世寂寞 2021-01-21 20:25

Note: This issue is already solved, finally I found that it\'s not cookies problem, the problem is on unserialize() function. The serialized cookie which

6条回答
  •  遥遥无期
    2021-01-21 21:00

    Look at both path and domain parameters for the setcookie function. Reference: setcookie @ PHP docs http://php.net/manual/en/function.setcookie.php

    Try this to set your cookie:

    if ($on_localhost) { // change this
        $domain = '.localhost';
    } else {
        $domain = '.webhoster.com'; // change this
    }
    setcookie(
        'settings',
        serialize($defaultSettings),
        time()+3600*24*30,
        '/',          // this is the path
        $domain       // this is the domain
    );
    

    Good luck!

提交回复
热议问题