登录Butto返回同一页面。而不是家

时间:2017-06-02 01:07:14

标签: php mysql mysqli xampp

我创建了一个页面。注册工作正常,并带我到主页,但注销后再次尝试登录。登录按钮将我重定向回注册页面。 请帮忙!我一遍又一遍地检查,无法找到任何错误。 的的login.php

<?php
if(isset($_POST['Login']))
{error_reporting(1);
    $connection = mysqli_connect('localhost','root','','uni-saga');
    if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


    $user=$_POST['username'];
    $pass=$_POST['password'];

    $que1=mysqli_query($connection,"select * from users where Email='$user' and Password='$pass'");
    $count1=mysqli_num_rows($que1);

    if($count1>0)
    {
        session_start();
        $_SESSION['tempsagauser']=$user;
        $que6=mysqli_query("select * from users where Email='$user'");
        $rec6=mysqli_fetch_array($que6);
        $userid=$rec6[0];

        $que2=mysqli_query($connection,"select * from user_profile_pic where user_id=$userid");
        $count2=mysqli_num_rows($que2);

        if($count2>0)
        {
            $que3=mysqli_query($connection,"select * from user_secret_quotes where user_id=$userid");
            $count3=mysqli_num_rows($que3);
            if($count3>0)
            {
                $que4=mysqli_query($connection,"select * from user_secret_quotes where user_id=$userid");

                while($rec=mysqli_fetch_array($que4))
                {
                    $que2=$rec[3];
                    $ans2=$rec[4];
                }
                if($que2=="" && $ans2=="")
                {
                    header("location:saga_files/saga_step/saga_step3/Secret_Question2.php");
                }
                else
                {

                    session_start();
                    $_SESSION['sagauser']=$user;
                    $query1=mysqli_query($connection,"select * from users where Email=$user");
                    $rec1=mysqli_fetch_array($query1);
                    $userid=$rec1[0];
                    mysqli_query($connection,"update user_status set status='Online' where user_id='$userid'");
                    header("location:saga_files/saga_home/Home.php");
                }

            }
            else
            {
                header("location:saga_files/saga_step/saga_step2/Secret_Question1.php");
            }
        }
        else
        {
            while($rec=mysqli_fetch_array($que1))
            {
                $Gender=$rec[4];
            }
            if($Gender=="Male")
            {
                header("location:saga_files/saga_step/saga_step1/Step1_Male.php");
            }
            else
            {
                header("location:saga_files/saga_step/saga_step1/Step1_Female.php");
            }
        }
    }
    else
    {
        $que5=mysqli_query($connection,"select * from users where Email='$user'");
        $count5=mysqli_num_rows($que5);

        if($count5>0)
        {
            header("location:Invalid_Password.php");
        }
        else
        {
            header("location:Invalid_Username.php");
        }
    }
}
?>

的index.php

<?php
    include("Login.php");
    include("saga_files/saga_index_file/saga_SignUp_file/SignUp.php");
?>
<html lang="en">
<head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>UniSaga</title>
        <link rel="stylesheet" href="css/bootstrap.min.css" />
        <link rel="stylesheet" href="css/style.css" />
        <link rel="stylesheet" href="css/ionicons.min.css" />
    <link rel="stylesheet" href="css/font-awesome.min.css" />
    <!--Google Font-->
    <link href="https://fonts.googleapis.com/css?family=Lato:300,400,400i,700,700i" rel="stylesheet">

    <!--Favicon-->
    <link rel="shortcut icon" type="image/png" href="images/fav.png"/>
    </head>
    <script>
    function time_get()
    {
        d = new Date();
        mon = d.getMonth()+1;
        time = d.getDate()+"-"+mon+"-"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes();
            }
</script>
<header id="header-inverse">
      <nav class="navbar navbar-default navbar-fixed-top menu">
        <div class="container">

          <!-- Brand and toggle get grouped for better mobile display -->
          <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index-register.html"><img src="images/logo.png" alt="logo" /></a>
          </div>

          </div>
          </nav>
          </header>
          <div id="lp-register">
        <div class="container wrapper">
        <div class="row">
            <div class="col-sm-5">
            <div class="intro-texts">
                <h1 class="text-white">UniSaga</h1>
                <p>Connect With Students from other Your University and Other Universities and get the latest news on what is Happening Around these learning Institutions. <br /> <br />What Are You Waiting For. Join Now And Experience It Like Never Before.</p>
             </div>
          </div>
            <div class="col-sm-6 col-sm-offset-1">
            <div class="reg-form-container">
            <div class="reg-options">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="#register" data-toggle="tab">Register</a></li>
                  <li><a href="#login" data-toggle="tab">Login</a></li>
                </ul><!--Tabs End-->
              </div>

              <!--Registration Form Contents-->
              <div class="tab-content">
                <div class="tab-pane active" id="register">
                  <h3>Register Now !!!</h3>
                  <p class="text-muted">Its Free and Always Will Be.</p>

                  <!--Register Form-->
                  <form  method="post" name="registration_form" id='registration_form' class="form-inline">
                    <div class="row">
                      <div class="form-group col-xs-6">
                        <label for="first_name" class="sr-only">First Name</label>
                        <input id="first_name" class="form-control input-group-lg" type="text" name="first_name" title="Enter first name" placeholder="First name"/>
                      </div>
                      <div class="form-group col-xs-6">
                        <label for="last_name" class="sr-only">Last Name</label>
                        <input id="last_name" class="form-control input-group-lg" type="text" name="last_name" title="Enter last name" placeholder="Last name"/>
                      </div>
                    </div>
                    <div class="row">
                      <div class="form-group col-xs-12">
                        <label for="email" class="sr-only">Email</label>
                        <input id="email" class="form-control input-group-lg" type="text" name="email" title="Enter Email" placeholder="Your Email"/>
                      </div>
                      <div class="form-group col-xs-12">
                        <label for="remail" class="sr-only">Re-Enter Email</label>
                        <input id="remail" class="form-control input-group-lg" type="text" name="remail" title="Enter Email" placeholder="Re-Enter Your Email"/>
                      </div>

                    </div>
                    <div class="row">
                      <div class="form-group col-xs-12">
                        <label for="password" class="sr-only">Password</label>
                        <input id="password" class="form-control input-group-lg" type="password" name="password" title="Enter password" placeholder="Password"/>
                      </div>
                    </div>
                    <div class="row">
                      <p class="birth"><strong>Date of Birth</strong></p>
                      <div class="form-group col-sm-3 col-xs-6">
                        <label for="month" class="sr-only"></label>
                        <select name="day" class="form-control" id="Day">
                          <option value="Day" disabled selected>Day</option>
                         <script type="text/javascript">

        for(i=1;i<=31;i++)
        {
            document.write("<option value='"+i+"'>" + i + "</option>");
        }

    </script>
                        </select>
                      </div>
                      <div class="form-group col-sm-3 col-xs-6">
                        <label for="month" class="sr-only"></label>
                        <select name="month" class="form-control" id="Month">
                          <option value="Month" disabled selected>Month</option>
                            <script type="text/javascript">

        var m=new Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
        for(i=1;i<=m.length-1;i++)
        {
            document.write("<option value='"+i+"'>" + m[i] + "</option>");
        }   
    </script>
                        </select>
                      </div>
                      <div class="form-group col-sm-6 col-xs-12">
                        <label for="year" class="sr-only"></label>
                        <select name="year" class="form-control" id="Year">
                          <option value="Year" disabled selected>Year</option>
                          <script type="text/javascript">

        for(i=2000;i>=1960;i--)
        {
            document.write("<option value='"+i+"'>" + i + "</option>");
        }

    </script>
                        </select>
                      </div>
                    </div>
                    <div  class="form-group gender">
                      <select name="sex" style="width:120;height:35;font-size:18px;padding:3;">
            <option value="Select Sex:"> Select Sex: </option>
            <option value="Female"> Female </option>
            <option value="Male"> Male </option>
        </select>
                    </div>
                    <div class="row">
                      <div class="form-group col-xs-6">
                        <label for="campus" class="sr-only">Campus</label>
                        <input id="campus" class="form-control input-group-lg reg_name" type="text" name="campus" title="Enter campus" placeholder="Your campus"/>
                      </div>
                      <div class="form-group col-xs-6">
                      <label for="county" class="sr-only"></label>
                        <select name="county" class="form-control" id="county">
                          <option value="county" disabled selected>County</option>
                          <option value="Baringo">Baringo</option>
                          <option value="Bomet">Bomet</option>
                          <option value="Bungoma">Bungoma</option>
                          <option value="Busia">Busia</option>
                          <option value="Elgeyo">Elgeyo Marakwet</option>
                          <option value="Embu">Embu</option>
                          <option value="Garissa">Garissa</option>
                          <option value="Homa">Homa Bay</option>
                          <option value="Isiolo">Isiolo</option>
                          <option value="Kajiado">Kajiado</option>
                          <option value="Kakamega">Kakamega</option>
                          <option value="Kericho">Kericho</option>
                          <option value="Kiambu">Kiambu</option>
                          <option value="Kilifi">Kilifi</option>
                          <option value="Kirinyaga">Kirinyaga</option>
                          <option value="Kisii">Kisii</option>
                          <option value="Kisumu">Kisumu</option>
                          <option value="Kitui">Kitui</option>
                          <option value="Kwale">Kwale</option>
                          <option value="Laikipia">Laikipia</option>
                          <option value="Lamu">Lamu</option>
                          <option value="Machakos">Machakos</option>
                          <option value="Makueni">Makueni</option>
                          <option value="Mandera">Mandera</option>
                          <option value="Meru">Meru</option>
                          <option value="Migori">Migori</option>
                          <option value="Marsabit">Marsabit</option>
                          <option value="Mombasa">Mombasa</option>
                          <option value="Muranga">Muranga</option>
                          <option value="Nairobi">Nairobi</option>
                          <option value="Nakuru">Nakuru</option>
                          <option value="Nandi">Nandi</option>
                          <option value="Narok">Narok</option>
                          <option value="Nyamira">Nyamira</option>
                          <option value="Nyandarua">Nyandarua</option>
                          <option value="Nyeri">Nyeri</option>
                          <option value="Samburu">Samburu</option>
                          <option value="Siaya">Siaya</option>
                          <option value="Taita">Taita Taveta</option>
                          <option value="Tana">Tana River</option>
                          <option value="Tharaka">Tharaka Nithi</option>
                          <option value="Trans">Trans Zoia</option>
                          <option value="Turkana">Turkana</option>
                          <option value="Uasin">Uasin Gishu</option>
                          <option value="Vihiga">Vihiga</option>
                          <option value="Wajir">Wajir</option>
                          <option value="West">West Pokot</option>
                            </select>
                      </div>
                    </div>
                    <button type="submit" name="signup" id="sign_button" class="btn btn-primary" / onClick="time_get()" >Register Now</button>
                  </form>

                </div>

                <div class="tab-pane" id="login">
                  <h3>Login</h3>
                  <p class="text-muted">Log into your account</p>

                  <!--Login Form-->
                  <form method="post" name="Login_form" id='Login_form'>
                     <div class="row">
                      <div class="form-group col-xs-12">
                        <label for="my-email" class="sr-only">Email</label>
                        <input id="my-email" class="form-control input-group-lg" type="text" name="username" title="Enter Email" placeholder="Your Email"/>
                      </div>
                    </div>
                    <div class="row">
                      <div class="form-group col-xs-12">
                        <label for="my-password" class="sr-only">Password</label>
                        <input id="my-password" class="form-control input-group-lg" type="password" name="password" title="Enter password" placeholder="Password"/>
                      </div>
                    </div>
                    <p><a href="Forgot_Password.php">Forgot Password</a></p>
                  <button name="Login" id="login_button" class="btn btn-primary">Login Now</button>
                  </form><!--Login Form Ends--> 

                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-sm-6 col-sm-offset-6">

            <!--Social Icons-->
            <ul class="list-inline social-icons">
              <li><a href="#"><i class="icon ion-social-facebook"></i></a></li>
              <li><a href="#"><i class="icon ion-social-twitter"></i></a></li>
              <li><a href="#"><i class="icon ion-social-googleplus"></i></a></li>
              <li><a href="#"><i class="icon ion-social-pinterest"></i></a></li>
              <li><a href="#"><i class="icon ion-social-linkedin"></i></a></li>
            </ul>
          </div>
        </div>
      </div>
    </div>

    <!--preloader-->
    <div id="spinner-wrapper">
      <div class="spinner"></div>
    </div>

    <!-- Scripts
    ================================================= -->
    <script src="js/jquery-3.1.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.appear.min.js"></script>
        <script src="js/jquery.incremental-counter.js"></script>
    <script src="js/script.js"></script>

    </body>

</html>
<?php
    include("saga_files/saga_index_file/saga_erorr_file/saga_erorr.php");
?>                  
</body>
</html>

1 个答案:

答案 0 :(得分:0)

1)您的会话不会保留其状态,例如在login.php页面处理完毕后,它会立即关闭。之所以发生这种情况,是因为您在session_start()中的代码中调用了login.php。因此,您必须将session_start()移至login.php中的第一行。没有代码应该驻留在它之前。 并且只使用它! (您使用session_start两次)

请参阅:https://tools.ietf.org/html/rfc1869

2)另外:Login_form需要action属性(login.php)。否则,表单将被发布到它所驻留的页面,例如index.php。所以:

<form method="post" action="login.php" name="Login_form" id="Login_form">

3)这里有一个错字(/):

<button type="submit" name="signup" id="sign_button" class="btn btn-primary" / onClick="time_get()" >Register Now</button>
祝你好运。