dongzhuxun5136 2014-07-03 20:25
浏览 103
已采纳

全局变量保持覆盖会话变量[重复]

This question is an exact duplicate of:

Below is a simple test code that I've produced from a bug I am facing right now.

session_start();  
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+ 1;
else
$_SESSION['views'] = 1;

$views = "hi";
echo "views = ". $_SESSION['views']; 

from what i believe $views and $_SESSION['views'] are completely different things. On a local test the script gives proper response first time 1 then 2 and then 3 and on and on.

The bug only exist on ipage hosting, there the same code gives output hi each time.

What am i missing?

</div>
  • 写回答

1条回答 默认 最新

  • doue2666 2014-07-03 20:31
    关注

    Yes, in theory $views and $_SESSION['views'] should be completely different things. However, there used to be a setting called register_globals in PHP. It has been marked as deprecated in version 5.3.0 and was removed from version 5.4.0, but people were using that quite a lot, because then you don't have to worry about superglobals and all that more involved stuff and can instead just type pretty much whatever you want.

    Anyway. Try to find out if your host is using an older version of PHP and if this function is activated on the server. I bet it is. Easiest way to do it: put the following script on the server and search for register_globals:

    <?php
    phpinfo();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧