我将验证代码改为:
<?php
session_start();
if(!session_is_registered($HTTP_SESSION_VARS['bm_id']))
{
        header("location:err.php");
        exit();
}
?>
也不行,以前是好好的啊!!!??真是一头雾水,我将验证代码单独成一文件err.php
然后在要验证的页面最上端include进去的,就是不行……

解决方案 »

  1.   

    把你的代码改成:
    <?php
    session_start();
    if(!session_is_registered($HTTP_SESSION_VARS['bm_id']))
    {echo "<script>alert(You must login first');location:er.php;</script>";
            exit();
    }
    ?>
    不知道可以不可以,我没有试过,但我以前是这样做的比如没有成功登录就返回原来页面就是用<?php
    session_start();
    if(!session_is_registered($HTTP_SESSION_VARS['bm_id']))
    {echo "<script>alert(You must login first');history.back();</script>";
            exit();
    }
    ?>
      

  2.   

    先Echo $_SESSION['bm_id'] 看看到底有没有注册上session
      

  3.   

    看看你的php里的设置文件对session的设置是否正确
      

  4.   

    to bonniewater(陪你去看海) 朋友
    我原本就好好的,根本没有动过它啊,session应该没有问题吧……
    以前用的好好的,代码没有更改,只是离开了几天而已……郁闷!
      

  5.   

    看看你的php版本是不是>=4.06的
    如果是:
    那么register_globals 为 on 的时候
    $HTTP_SESSION_VARS['bm_id'] 才等价于$bm_id现在的问题是:你的session一定没有注册成功!
      

  6.   

    感觉上session真的好像没有注册到,问题何在呢?
      

  7.   

    if(!session_is_registered($_SESSION['bm_id']))
    这样看看
      

  8.   

    我的是php-4.3.4的,不管register_globals是否已经打开
    我都可以使用$HTTP_SESSION_VARS或者$_SESSION来取得变量值啊
    况且还是打开的,真的郁闷极了,几天前还好好的
    只是离开几天,现在要上交论文程序了,就麻烦来了
    我再次声明,代码是没有改的,几天前还好好的
    现在突然之间为何就获取不到session了呢!!!
      

  9.   

    if(!session_is_registered($_SESSION['bm_id']))
    这样看看
    ------------------------
    也不行……
      

  10.   

    对不起上面我有 句话说错了 !
    在php版本4.06以前有个bug
    register_globals 为 on 的时候
    $HTTP_SESSION_VARS['bm_id'] 有时候会等价于$bm_id
      

  11.   

    E文不太好,不知道说的对不对~你自己看一下原文 不要意思~~~-_-!!PHP4.06的改进  
     
      Fixed memory fragmention problem which could lead to web server processes growing much more than they should. (Andi, Zend Engine) 
      Made $HTTP_SESSION_VARS['foo'] and $foo be references to the same value when register_globals is on. (Andrei) 
      Fixed disk_free_space() and disk_total_space() under FreeBSD. (Jon) 
      Fixed readfile/passthru losing resources during connection abort (Sascha)
      . 
      .
      . 
      
     
      

  12.   

    Made $HTTP_SESSION_VARS['foo'] and $foo be references to the same value when register_globals is on.
    这个不是bug啊,只是打开了全局变量而已,不过跟我的问题好像也没有多大关系
    当register_globals 为on的时候,我可以在别的页面自动取得$bm_id
    如果register_globals为off则必须$_SESSION['bm_id']或者$HTTP_SESSION_VARS['bm_id']
    才能取得值,我现在费解的是我的逻辑判断都没有错啊,但就是不能达到目的
      

  13.   

    我将相关的程序段给出来,如下:
    -----------------------------------------------------
    表单提交:
    <form name="form1" method="post" action="login_check.php">
                      <td height="120" align="center">
                        <table width="180" height="110" border="0" cellpadding="3" cellspacing="0" bgcolor="#CCCCCC" style="font-size: 12px;">
                          <tr>
                            <td width="60" height="20"> <div align="right">用户名:</div></td>
                            <td height="20" colspan="2"> <input name="username" type="text" id="username" size="12" maxlength="16">
                            </td>
                          </tr>
                          <tr>
                            <td width="60" height="20"> <div align="right">密码:</div></td>
                            <td height="20" colspan="2"> <input name="password" type="password" id="password" size="12" maxlength="20">
                            </td>
    --------------------------------------------------------
    //login_check.php
    $query="select * from userinfo where bm_id = '$username' and bm_pass = '$password'";
            $result=mysql_query($query);
    isset($_POST['username'])) {
      if(login($username,$password)) {
        header("Location: main.php");
        exit();
      }else
         echo "请输入正确的用户名和口令";
    //bm_id和bm_pass是数据表里的字段,这段程序用来判断用户提交的用户名和密码是否正确
    //如果正确就转到main.php页面如下是main.php里边的验证代码:检测session是否已注册,未注册则error.php,否则就是main.php的内容
    <?php
    session_start();
    if(!session_is_registered($_SESSION['bm_id']))
    {
    header("location:error.php");
            exit();
    }
    ?>
    有什么问题呢???
      

  14.   

    你的login_check.php里边没有注册session吧
      

  15.   

    修改登陆认证代码后,问题得到解决,但费解的是
    先前的为何不行了呢?
    <?php
    session_start();
    if (isset($_POST['username']) && isset($_POST['password']))
    {........
    $_SESSION['bm_id'] =$_SESSION['username'];
                    $_SESSION['bm_pass'] =$_SESSION['bm_pass'];
    ...........}
      

  16.   

    我很奇怪你以前的程序是怎么运行起来的你的login_check.php好象并没有注册session啊,那么当然没有session值了,我把你的这个程序改了一下,你试试看
    $query="select * from userinfo where bm_id = '$username'";
    $result=mysql_query($query);
    if(mysql_num_rows($result)=="")

      echo"没有该用户!";
    }
      else if($_POST["password"]!=mysql_result($result,0,"bm_pass"))
          {
           echo"你的密码错误!";
          }
             else
                {
                 session_start();
                 $_session['bm_id']=$_POST["username"];
                 $_session['bm_pass']=$_POST["password"];
                   if(!session_is_registered($_SESSION['bm_id']))
                        {
                         header("location:error.php");
                         exit();
                         }
                            else
                              Header("location:你的目标文件");
                 }