doudao9896 2016-08-10 05:09
浏览 9

Cookie设置与旧值

I'm using the code:

IF (isset($_GET['s']))
{
    $sessie = $_GET['s'];
}
ELSE
{
    $sessie = 'I';
}
$cookie = 'JaiDje_Page';
setcookie($cookie, $sessie);
$WDpag = $_COOKIE[$cookie];
echo $WDpag."-".$_COOKIE[$cookie]."-".$sessie."<br>";

After a new value for $sessie (menu choise) the strange thing is that the first time the page is loaded, $WDpag and $_COOKIE[$cookie] are giving the old value and $sessie is giving the new value. After a page refresh all three values are the same.

So after making a choise in the menu the following is echos (exampel)

I-I-Z

than after a page refresh (F5)

Z-Z-Z

It seems that the cookie is one step behind the choise in my menu.

What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • duannao1920 2016-08-10 05:13
    关注

    $_COOKIE is set when the page loads so If you want immediate access, you can set $_COOKIE['variable'] direct.

    so do like this

    //setcookie($cookie, $sessie);
    $_COOKIE[$cookie] = $sessie;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大