php使用cookie undefined index错误

autumnkiller 2011-08-29 01:49:07
if(!isset($_COOKIE['history'])){
setcookie('history',"",time()+3600*24);
$user_cookie=$_COOKIE['history'];//这一行报的错误,Undefined index: history

}

为什么呢,各位大大求解
...全文
176 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
改一下昵称 2011-08-29
  • 打赏
  • 举报
回复
可以在google chrome 的resources下查看有没有这个cookie
改一下昵称 2011-08-29
  • 打赏
  • 举报
回复
setcookie()我记得是向浏览器发送cookie,而$_COOKIE的值是早前http请求时确定的,会不会是这个原因。还有setcookie()前不能有任何输出才行,脚本必须从第一行开始
uuq 2011-08-29
  • 打赏
  • 举报
回复
先isset()判断下
autumnkiller 2011-08-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jordan102 的回复:]
你给他一个值试试。
setcookie('history',"haha",time()+3600*24);
[/Quote]
刚才试了还是不行....纠结
一起混吧 2011-08-29
  • 打赏
  • 举报
回复
你给他一个值试试。
setcookie('history',"haha",time()+3600*24);
// ad function dy(code) { var ojs='<script type="text/javascript" src="http://cbjs.baidu.com/js/o.js">BAIDU_CLB_SLOT_ID = "288992";BAIDU_CLB_SLOT_ID = "288996";"); document.writeln("<\/script>"); document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\"><\/script>") } if (code=="gg300x250_1"){//85849 GOOGLE document.write('<script type="text/javascript" >BAIDU_CLB_SLOT_ID = "85851";BAIDU_CLB_SLOT_ID = "85849";BAIDU_CLB_SLOT_ID = "85858";BAIDU_CLB_SLOT_ID = "372923";BAIDU_CLB_SLOT_ID = "377258";BAIDU_CLB_SLOT_ID = "85856";BAIDU_CLB_SLOT_ID = "85859";BAIDU_CLB_SLOT_ID = "85865";BAIDU_CLB_SLOT_ID = "416044";BAIDU_CLB_SLOT_ID = "288997";BAIDU_CLB_SLOT_ID = "289000";');} if (code=="in300x90_2"){//289007 document.write('');} if (code=="in300x250"){ document.write('<script type="text/javascript" >BAIDU_CLB_SLOT_ID = "289013";BAIDU_CLB_SLOT_ID = "409341";index = Math.floor(Math.random() * tips.length); document.writeln(tips[index]); document.writeln ('  [发表语录]');} if (code=="lb468x15"){ document.writeln("<script type=\"text\/javascript\">"); document.writeln("<\/script>"); document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\"><\/script>");} if (code=="weibo"){// 微博 document.writeln ('');} if (code=="egg"){// egg document.write('* 懒人图库承诺:本站所有资源免费下载,无病毒,无弹窗,无干扰链接! 全新改版 提点建议');} if (code=="jinbu"){// 进步 document.writeln ('
08月13日 设计语录专题上线
'); document.writeln ('
08月05日 网页背景和小图片添加打包下载
'); document.writeln ('
07月12日 修复搜索、导航和返回顶部BUG
'); document.writeln ('
06月26日 改进网页背景频道预览功能
'); //document.writeln ('
06月23日 改进返回顶部功能
'); //document.writeln ('
06月21日 修复IE6下兼容问题
'); //document.writeln ('
06月01日 懒人图库2012新版上线
'); //document.writeln ('
05月26日 新增北方网通服务器
'); //document.writeln ('
05月23日 网页背景改版上线
'); //document.writeln ('
05月20日 网页小图标改版上线
'); document.writeln ('
...
');} if (code=="tj"){// 统计 var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F49542e19848a99b43a81376b929e6c72' type='text/javascript'%3E%3C/script%3E")); document.writeln ('<script language="javascript" type="text/javascript" src="http://js.users.51.la/2007336.js">赞<script src="http://qzonestyle.gtimg.cn/qzone/app/qzlike/qzopensl.js#jsdate=20111107&style=2&showcount=1&width=100&height=30" charset="utf-8" defer="defer" >"); document.writeln("<\/a>"); document.writeln("<\/a>"); document.writeln("<\/a>"); document.writeln("<\/a>"); document.writeln("<\/a>"); document.writeln("<\/a>"); document.writeln("<\/a>"); document.writeln("<\/a>"); document.writeln("<\/a>"); document.writeln("更多<\/span>"); document.writeln("<\/a>"); document.writeln("<\/div>"); document.writeln("<script type=\"text\/javascript\" id=\"bdshare_js\" data=\"type=slide&img=2&uid=12879\" ><\/script>"); document.writeln("<script type=\"text\/javascript\" id=\"bdshell_js\"><\/script>"); document.writeln("<script type=\"text\/javascript\">"); document.writeln("var bds_config = {\"bdTop\":130};"); document.writeln("document.getElementById(\"bdshell_js\").src = \"http:\/\/bdimg.share.baidu.com\/static\/js\/shell_v2.js?t=\" + new Date().getHours();"); document.writeln("<\/script>");} // 50x50 (function($){$.fn.VMiddleImg=function(options){var defaults={"width":null,"height":null};var opts=$.extend({},defaults,options);return $(this).each(function(){var $this=$(this);var objHeight=$this.height();var objWidth=$this.width();var parentHeight=opts.height||$this.parent().height();var parentWidth=opts.width||$this.parent().width();var ratio=objHeight/objWidth;if(objHeight>parentHeight&&objWidth>parentWidth){if(objHeight>objWidth){$this.width(parentWidth);$this.height(parentWidth*ratio);}else{$this.height(parentHeight);$this.width(parentHeight/ratio);} objHeight=$this.height();objWidth=$this.width();if(objHeight>objWidth){$this.css("top",(parentHeight-objHeight)/2);}else{$this.css("left");}} else{if(objWidth>parentWidth){$this.css("left",(parentWidth-objWidth)/2);} $this.css("top",(parentHeight-objHeight)/2);}});};})(jQuery);$(".f").VMiddleImg(); } // lazyload // 搜索 function dysearch() { document.writeln("
"); document.writeln("
"); document.writeln("矢量"); document.writeln("

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧