PHP cookie在两个页面之间传递变量 [英] PHP cookies to pass variables between two pages
本文介绍了PHP cookie在两个页面之间传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用会话和GET / POST方法,但是我想使用cookie来实现。我在page1.php上的代码是:
I am aware that I can use sessions and GET/ POST method but I would like to achieve this using cookies. My code on page1.php is :
$_COOKIE['varname'] = $id;
,在page2.php上是:
and on page2.php is:
$id = $_COOKIE['varname'];
我在浏览器上收到以下通知:未定义索引$ id
是什么问题
I get the following notice on my browser: Undefined index $id What is the problem with my code?
推荐答案
尝试使用 setcookie('varname',$ id)
然后
if (isset($_COOKIE['varname']){ echo $_COOKIE['varname']; }
这篇关于PHP cookie在两个页面之间传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文