drn5375 2013-08-01 14:48
浏览 22
已采纳

php $ _SESSION var非常奇怪的问题

Maybe I am too tired... but I can't figure out how the session id in this piece of code becomes 143 from 149.

echo "session id is".$_SESSION['userid'];
$smarty->assign('itemresults',$arr2);

$_SESSION['userid']

if (isset($_REQUEST['id']))
{
    $userid=$_REQUEST['id'];
}
else
{
echo "session id 1 is".$_SESSION['userid'];
    $userid=$_SESSION['userid'];
}
echo "session id 2 is".$_SESSION['userid'];

Output:

session id is149session id 2 value is143

UPDATE:

Ok just found out that If I change the var $userid the issue is no more but why assigning a value to $userid will modify $_SESSION['userid'] as well ??

The below code works:

if (isset($_REQUEST['id']))
{
    $userid2=$_REQUEST['id'];
}
else
{
echo "session id 1 value".$_SESSION['userid'];
    $userid2=$_SESSION['userid'];
}
  • 写回答

2条回答 默认 最新

  • doutang3815 2013-08-01 15:21
    关注

    you have register_globals turned on, which is a potential security hole (very easy to fall into as you've noticed), and a dead end (it's gone from 5.4).

    http://www.php.net/manual/en/ini.core.php#ini.register-globals:

    Whether or not to register the EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables.

    As of PHP 4.2.0, this directive defaults to off.

    Please read the security chapter on Using register_globals for related information.

    Warning

    This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作