Cookies not working on different pages

后端 未结 9 1664
长发绾君心
长发绾君心 2020-12-03 17:19

Ok I have a cookie set, and I can clearly see it if I go to private data in Firefox... ok so when I echo it on one page in a certain directory it works, (www.example.com/dir

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 17:56

    setcookie('cookie_username', $cookie_username, time() + (86400 * 30), "/"); // 86400 = 1 day,  '/' denotes cookie available in entire directory.
    

    and in another page:

    $username = $_COOKIE['cookie_username'];
    

    also make sure that browser is not blocking cookies.

    If you want to use cookies in sub domain also:

    setcookie('cookie_username', $cookie_username, time() + (86400 * 30), "/", ".subdomain.com"); // 86400 = 1 day,  '/' denotes cookie available in entire directory.
    

提交回复
热议问题