dongzhuxun5136 2014-07-03 12: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 12: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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部