php cookie失效怎么办-PHP问题

资源魔 35 0

php cookie生效是由于当setcookie中第4个参数为空的话,默许只正在以后目次失效,其处理方法就是增加第4个参数,语句为“setcookie("id",$id, time()+36002430 ,'/');”。

PHP设置cookie有效成绩缘由和处理计划

正在某个页面中应用setcookie来设置cookie,例如

setcookie("id",$id, time()+36002430);

然而回到首页之后发现不失效,用javascript:alert(document.cookie)外面为空,PHP外面的$_COOKIE也是不数据。

跑到PHP官网查看setcookie的阐明,官网的例子也是这样的,然而细心看来参数阐明之后就发现成绩了。

setcookie的第4个参数是path

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.

也就是说假如第4个参数为空的话,默许只正在以后目次失效,普通状况下是不成绩的。

然而我的站点设置了rewrite,把index.php给隐去了,以是设置的cookie变为只正在该页面无效。

处理计划就是增加第4个参数

setcookie("id",$id, time()+36002430 ,'/');

更多相干常识,请拜访PHP中文网!

以上就是php cookie生效怎样办的具体内容,更多请存眷资源魔其它相干文章!

标签: php cookie php教程 php故障解决 php使用问题

抱歉,评论功能暂时关闭!