我在login.php的有用
session_start();//启动会话
Session_register("userID");//创建会话变量
创建session对象。
我的session.php代码是
<?
  session_start();
  //检查userID是否被注册为session
  if(!isset($_SESSION['userID']))
  {
   echo "<script>";
   echo "alert(\"Please Sign in before\");";
   echo "location.href=\"javascript: window.open(\'index.php\',\'_parent\')\";";
   echo "</script>";
  }
?>现在我是set2.php,将session.php作为外挂来控制用户有没有登入。可是在login.php显示到我已登入成功,但是跳转到set.php就弹出对话框说我没登入!

解决方案 »

  1.   

    login.php代码
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <link href="smallwindow.css" rel="stylesheet" type="text/css" />
    </head><body>
    <div id="downbg">
      <div id="upbg">
    <p class="pc">Login</p>
    <form method="post" name="webadress" action="login_process.php">
    <p class="pcss">User ID :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="userID" type="text" /></p>
    <p class="pcss">Password:&nbsp;<input name="password" type="password" /></p>
    <p class="pc"><input name="reset" type="reset" value="reset" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input name="login" type="submit" value="login"/></p>
    </form>
      </div>
    </div>
    </body>
    </html>
    login_process.php代码
    <?
      include("db_conn.php");
      include("randpass.php");  if($_POST[userID]=="")
      {
      echo "<script>";
      echo "location.href=\"loginwrong4.html\";";
      echo "</script>";
      }
      else
      {
      //取出用户表中是否有此用户
      $SQLStr="select * from users where UserId='$userID'";
      $res=mysql_query($SQLStr);   //若有此用户
      if(mysql_num_rows($res)>0)
      {
      $row=mysql_fetch_array($res);
      //判断用户密码是否正确
      if($row['PassWord']==$password)//密码正确
      {
      session_start();//启动会话
      Session_register("userID");//创建会话变量   if($row[g_times]>0)
      {
      /*************判断用户是否已经完成了特定的步骤******************/
      $SQLStr="select * from stepcontrol where UserId='$userID'";
      $res=mysql_query($SQLStr);
      if(mysql_num_rows($res)>0)
      {
      $row=mysql_fetch_array($res);
     
      if($row['score']==null)
      {
      echo "<script>";
      echo "location.href=\"tips2.html\";";
      echo "</script>";
      }
      if($row['step2']==null)
      {
      echo "<script>";
      echo "window.top.location.href=\"set3.php\";";
      echo "</script>";
      }
      if($row['step2']==1)
      {
      echo "<script>";
      echo "window.top.location.href=\"present.php\";";
      echo "</script>";
      }
      }
      else
      {
      $SQLins="insert into stepcontrol(UserId) values('$userID')";
              mysql_query($SQLins);   echo "<script>";
      echo "location.href=\"tips2.html\";";
      echo "</script>";
      }
      }
      else
      {
      echo "<script>";
      echo "location.href=\"loginwrong2.html\";";
      echo "</script>";
      }
      }
      else//密码错误
      {
      echo "<script>";
      echo "location.href=\"loginwrong5.html\";";
      echo "</script>";
      }
      }
      else
      {
       echo "<script>";
       echo "location.href=\"loginwrong1.html\";";
       echo "</script>";
      }
      }
    ?>set2.php代码只有
    <?
     include("session.php");
    ?>其他的都是html代码
      

  2.   

    PHP社区都不鼓励使用Session_register(),
    $_SESSION['userID']不行吗?
      

  3.   

    用$_SESSION['userID']报错!
    这个session问题在本地测试时并没有出现,在我把网站传上空间后就出现这个问题的
      

  4.   

    跳转到set.php就说没登陆?你set.php的代码呢?
      

  5.   

    然后也许是我看漏了,你在哪里给session付值啊?
      

  6.   

    不好意思!!是set2.php页面弹出没登入的信息!我没有set.php页面,是set2.php页面!session在login_pricess.php页面有复值
      

  7.   

    session_start()要放在文件的最开头,你把它移上去看看呢?
      

  8.   

    你打印$_SESSION['userID']报的是什么错?
      

  9.   

    配置环境是怎么样的,iis+php下,需要手动配置session
      

  10.   

    PHP+MYSQL+APACH
    是上传到国外空间的
      

  11.   

    我的意思是说,你echo $_SESSION['userID'],他给出的结果什么?还有,你哪里有付值啊?我怎么没看到?反正你首先要把session_start放到文件的最开头,前面不能有任何输出语句,html也不行,我曾经犯过这样的错。
      

  12.   

    还有,Session_register是注册变量,你每次运行set2.php时,都要注册一次userID这个变量,那应该就等于每次都是新变量了,你set2.php就这一句代码?