查询PHP cookie [英] Query about PHP cookie

查看:70
本文介绍了查询PHP cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP新手,正在使用PHP cookie,但遇到了无法正确设置cookie的问题。
这是Set Cookie的语句

I'm new PHP guy and I'm using PHP cookie and I'm facing a problem that the cookie can not be set correctly. Here is the statement of Set Cookie


setcookie('cookieusername',$ username,100000);

setcookie('cookieusername', $username, 100000);

和获取Cookie的语句

and the statement of Get Cookie


$ cookieusername = $ _COOKIE [ cookieusername];

$cookieusername = $_COOKIE["cookieusername"];

问题是, $ _ COOKIE [ cookieusername]的值; 未定义。

我不知道问题是什么。我已经厌倦了将cookie路径设置为 /,但是仍然无法使用。

I don't know what the problem is. I have tired to set the cookie path to '/' but which was still not work.

推荐答案

而不是:

setcookie('cookieusername', $username, 100000);

您必须做的事情:

setcookie('cookieusername', $username, time() + 100000);

原因是第三个参数是到期时间(作为Unix时间戳(自时期)),而不是到期之前的时间。而这是手册的链接

The reason is that the third parameter is the expiry time (as a Unix timestamp (number of seconds since the epoch)), not the time until expiry. And here's the link of manual.

这篇关于查询PHP cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆