var cookiestring = new string(document.cookie)
var cookieheader = 'test='
var beginposition = cookiestring.indexof(cookieheader)
if (beginposition document.write("我不知道");
var then = new date()
then.settime(then.gettime() + 60*1000 )
document.cookie = 'test=yes;expires='+ then.togmtstring()
}
$cookie = $_COOKIE['name'];//接收指定cookie
$header = 'test=';
//没有找到指定的内容
if( strpos($cookie,$header) === false){
echo '我不知道';
//重新设置过期时间
$_COOKIE('name',值,过期时间);
}
$cookie = $_COOKIE['name'];//接收指定cookie
$header = 'test=';
//没有找到指定的内容
if( strpos($cookie,$header) === false){
echo '我不知道';
//重新设置过期时间
$_COOKIE('name',值,过期时间);
}
凡事都有个度,php 不能代替 js 完成的工作
你的那段 js 代码完成的是这样的工作:如果名为 test 的 cookie 变量不存在,则创建他
等价的 php 代码是 if(! isset($_COOKIE['test'])) setcookie('test', 'yes', time()+60);
但是 js 是运行于 2 次 php 之间的,于是效果也是不一样的
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号