doupao1530 2018-04-27 01:23
浏览 74
已采纳

如何从具有不同URL的网页访问cookie信息

My code set a cookie as shown in below; I cannot get the cookie information from a page with a different URL... Is there something wrong in my code? Please let me know if you have any question.

zzz.php;

  setcookie ("mail", $mail, time()+3600*24*365*10);
  setcookie ("name", $name, time()+3600*24*365*10);
  setcookie ("password", $password, time()+3600*24*365*10);
  .....
  http_response_code(301);
  header("Location: ../xxx.php");

xxx.php;

echo $_COOKIE['mail'];

On xxx.php , nothihg comes up.

  • 写回答

1条回答 默认 最新

  • douwei8295 2018-04-27 01:44
    关注

    http://php.net/setcookie

    The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.

    If you want the cookie to be available in the parent directory, you'll need to set the path for the cookie. Easiest way to do that is to set all your cookies to a path of /, so the cookies are available everywhere on that domain:

    setcookie ("mail", $mail, time()+3600*24*365*10, '/');
    setcookie ("name", $name, time()+3600*24*365*10, '/');
    setcookie ("password", $password, time()+3600*24*365*10, '/');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao