dousi1970 2016-12-19 18:54
浏览 21
已采纳

在第一次和第二次请求期间,此PHP代码的输出是什么?

This is most likely a PHP noobie question.

To test some server caching configuration, I added the following code to my test suite:

<?php

if (array_key_exists('visited', $GLOBALS))
{
   print_r("We have already met");
} else {
   print_r("Hello ShimmerCat");
}

$GLOBALS['visited']=1;
?>

I'm expecting this code to take differents path of the branch during a first and second request, but it is returning the second message always. How can I achieve what I want?

  • 写回答

1条回答 默认 最新

  • douqixia7942 2016-12-19 19:02
    关注

    PHP itself is stateless, meaning every time a user visits a PHP page, the whole operation is done from scratch with each variable being defined as in the script.

    If you want to store data between views, the basic way is with cookies. If you want the details of what's remembered to be secure, use session cookies.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办