简体   繁体   English

在colorbox中使用的PHP Cookies

[英]PHP Cookies using in colorbox

I create a cookie in login.php 我在login.php中创建一个cookie

setcookie("mes_mod_kull",$userid,time() + 3600,'/');

I have a link for open colorbox like this : 我有一个打开颜色框的链接,如下所示:

<a href="file_add.php" class="colorbox">Add File</a>

In file_add.php I have to use cookie. 在file_add.php中,我必须使用cookie。 I mean, I have to reach to cookie which I was created in login.php 我的意思是,我必须到达在login.php中创建的cookie

I use this code for test cookie value : print $_COOKIE["mes_mod_kull"]; 我将以下代码用于测试Cookie值: print $_COOKIE["mes_mod_kull"]; But there is an error here : Notice: Undefined index: mes_mod_kull in.......... 但是这里有一个错误:注意: Undefined index: mes_mod_kull in..........

Can someone help me ? 有人能帮我吗 ?

The problem is in setcookie function. 问题出在setcookie函数中。 It's need to define domain. 需要定义域。

I change the following code 我更改以下代码

setcookie("mes_mod_kull",$userid,time() + 3600,'/');

to

setcookie("mes_mod_kull",$userid,time() + 3600,'/','mydomain.com');

and it's worked. 并且有效。 It's little bit ridiculous. 这有点荒谬。

Assuming your print call is in the SAME script as the setcookie, you'll have to wait until the NEXT execution of the script for $_COOKIE to be populated with that new cookie. 假设您的打印调用以setcookie的形式出现在SAME脚本中,则必须等到脚本的NEXT执行后,$ _ COOKIE才会被该新cookie填充。 PHP builds/populates the superglobal (_GET, _POST, _COOKIE, etc...) ONCE while the script is initialization, then does not touch them again for the life of the script. PHP构建/填充超全局(_GET,_POST,_COOKIE,等...) 一次 ,而剧本是初始化,则不会再为脚本的生活接触他们。 setcookie update $_COOKIE for you. setcookie为您更新$ _COOKIE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM