标题不会重定向到任何页面

时间:2014-03-21 03:44:13

标签: php

在localhost上一切正常但是当我把它放在实时服务器上时我的标题在登录后没有重定向因此没有设置会话所以我的用户信息没有显示在右上角,直到我手动刷新页面或导航到其他页面。请注意,它不会重定向到我放置的任何页面。

的header.php:

session_start();
$userid=$_SESSION['userid'];
$username=$_SESSION['username'];

的index.php:

include "header.php";
if($username && $userid)
   {
      echo "You are logged in as <b>$username</b>";
   }
 else
   {
    $form="<form action='index.php' method='post'>
           <table>
              <tr>
              <td>Username:</td>
              <td><input type='text' name='user'></td>
              </tr>

              <tr>
              <td>Password:</td>
              <td><input type='password' name='pass'></td>
              </tr>

              <tr>
              <td><input type='submit' name='submit' value='login'></td>
              </tr>

              <tr>
              <td><a href='register.php'>Register</a></td>
              <td><a href='forgotpass.php'>Forgot password?</td>
              </tr>
           </table>
           </form>";

  if(isset($_POST['submit']))
   {
    $user=htmlentities($_POST['user']);
    $pass=htmlentities($_POST['pass']);

    if($user)
      {
         if($pass)
          {
           require 'connect.php';
           $pass=md5(md5("123".$pass."456"));
           $query=mysqli_query($conn,"SELECT*FROM user WHERE username='$user'");
           $numrows=mysqli_num_rows($query);

           if($numrows==1)
              {
                $row=mysqli_fetch_assoc($query);
                $dbusername=$row['username'];
                $dbid=$row['id'];
                $dbpass=$row['password'];
                $dbactive=$row['active'];

                if($pass==$dbpass)
                  {
                    if($dbactive==1)
                      {
                       $_SESSION['username']=$dbusername;
                       $_SESSION['userid']=$dbid;
                       header("Location:index.php");
                      }
                     else
                      {
                        echo "You must activate your account.$form";
                      }
                  }
                else 
                  {
                    echo "Incorrect password.$form";
                  }
              }
            else
              {
                echo "Incorrect username.$form";
              }

            mysqli_close($conn);
          }
        else
          {
           echo "You must enter password.$form";
          }
       }
     else
       {
        echo "You must enter username.$form";
      }
   }
else
  {
    echo $form;
  }
}

0 个答案:

没有答案