登录代码:<?php
if($_GET['ok']=="login")
{
    require('config.inc.php');
    session_start();//打开SESSION
    $username=$_POST['UserName'];
    $password=md5($_POST['Password']);
    $sql="select * from admin where username='$username' and password='$password'";
    $result=mysql_query($sql);
    $num_rows=mysql_num_rows($result);
        if($num_rows)
        {
                $_SESSION["admin"] = "admin@#$%admin";
                $_SESSION['adminuser'] = $username;                //echo "<script language=javascript type=text/JavaScript>";
                //echo "location.href='main.php';";
                //echo "</script>";
                //直接header
                header("location: main.php");
        }        
        else{
        echo "<script language=javascript type=text/JavaScript>";
        echo "alert('错误的用户名或密码!');";
        echo "history.back(-1);";
        echo "</script>";
        }
}
?>

解决方案 »

  1.   

    主要就是楼上的情况
    1.没开session_start();
    2.转向错误
    转向错误可以将转向代码改成文字出
    再一步步加上转向代码就可以知道那里出问题
      

  2.   

     <?php
    session_start()
    if($_GET['ok']=="login")
    加这一句。
      

  3.   

    用得着session_start吗?最好不要随便加这句。
      

  4.   

    呵呵,他里面用到了session保存,肯定要用的。
    $_SESSION["admin"] = "admin@#$%admin";
    $_SESSION['adminuser'] = $username;不过位置可以换下if($_GET['ok']=="login") {
    session_start();
      

  5.   


    需要时就用,不需要不要用,SESSION是有些影响性能的。
      

  6.   

    设置session和取session的时候必须加session_start();
      

  7.   

    我改为header以后,报错
    Warning: Cannot modify header information - headers already sent by (output started at d:\www\ustcori\wwwroot\admin\loginCh.php:2) in d:\www\ustcori\wwwroot\admin\loginCh.php on line 28
    我查了下这个错误,说可能是前后有空行什么的,我去掉了还是不行
      

  8.   

    那空格或行可能是特殊字符,看不到的...
    要用HEX 编辑器看
      

  9.   

    用简单的记事本编辑一下,然后header()前不要有任何输出语句