2014-04-10 39 views
0

看起來,處理表單發佈後,它會得到一個標題,然後在重新加載時,源格式會隨着css div消失而失效,會話不起作用。那麼會話設置和頭帶給用戶返回到頁面的消息,以在日誌中的成功,這是一個測試文檔hense -標題或會話問題

<?php session_start(); ?> 
<html> 
    <head> 
     <title>Webpage</title> 
     <link rel="stylesheet" type="text/css" href="Style.css"> 
    </head> 
    <body>  
     <Div align="center"> 
      <Formlad> 
       <form action="loginprocess.php" method="post" target="_self"> 
        Username: <input type="text" name="username" Value='' required><BR> 
        Password: <input type="password" name="pass" Value='' required><BR> 
        Submit: <input type="submit" value="Submit" required> 
       </form> 
      </Formlad> 
     </Div> 
     <div align="center"> 
      <Errorbox> 
       <?php 
        echo ($_SESSION['Logindets']);     
       ?> 
      </Errorbox> 
     </div> 
    </body> 
</html> 
這樣得到的數據發佈到處理頁面

好一次成功嘗試的不合邏輯的重定向。

<html> 
    <?php 
     $tmpusername=$_POST["username"]; 
     $tmppassword=htmlspecialchars($_POST["pass"]); 



     $con=mysqli_connect("localhost","usr","password","database") or die(mysql_error()); 
     $pnquery = "SELECT max(ID) AS ID from table" ; 
     $result = mysqli_query($con,$pnquery); 
     $IDtemp=(mysqli_fetch_array($result)); 
     $IDmax=$IDtemp['ID']; 

     $IDc=1; 
     While ($IDc<>($IDmax+1)){ 
      $pnquery = "SELECT Username from table Where ID ='$IDc'" ; 
      $result = mysqli_query($con,$pnquery); 
      $Usrtemp=(mysqli_fetch_array($result)); 
      if ($tmpusername==$Usrtemp['Username']){ 
       $nothiredu=1; 
      } 
      $IDc=$IDc+1; 
     } 

     $IDc=1; 
     While ($IDc<>($IDmax+1)){ 
      $pnquery = "SELECT Password from table Where ID ='$IDc'" ; 
      $result = mysqli_query($con,$pnquery); 
      $Usrtemp=(mysqli_fetch_array($result)); 
      if ($tmppassword==$Usrtemp['Password']){ 
       $nothiredp=1; 
      } 
      $IDc=$IDc+1; 
     } 

     $IDc=1; 
     While ($IDc<>($IDmax+1)){ 
      $pnquery = "SELECT Username from table Where ID ='$IDc'" ; 
      $result = mysqli_query($con,$pnquery); 
      $Usrtemp=(mysqli_fetch_array($result)); 
      if ($tmpusername==$Usrtemp['Username']){ 
       $hiredu=1; 
      } 
      $IDc=$IDc+1; 
     } 

     $IDc=1; 
     While ($IDc<>($IDmax+1)){ 
      $pnquery = "SELECT Password from table Where ID ='$IDc'" ; 
      $result = mysqli_query($con,$pnquery); 
      $Usrtemp=(mysqli_fetch_array($result)); 
      if ($tmppassword==$Usrtemp['Password']){ 
       $hiredp=1; 
      } 
      $IDc=$IDc+1; 
     } 
     If (($nothiredu==1) and ($nothiredp==1)){ 
      $_SESSION['Logindets']='STUFfff.......'; 
      header("Location: http://localhost/Login.php"); 
      exit; 
     } 
     if (($hiredu==1) and ($hiredp==1)){ 

      $pnquery = "SELECT ID from table Where Username ='$tmpusername'" ; 
      $result = mysqli_query($con,$pnquery); 
      $IDtemp=(mysqli_fetch_array($result)); 
      $_SESSION['Logindets']='YOUR IN SON WHOOOP'; 
      $_SESSION['Loginsuc']=1; 
      $_SESSION['LoginTime'] = time(); 
      $_SESSION['LoginID'] = $IDtemp['ID']; 
      $_SESSION['LoginUsr'] = $tmpusername; 
      header("Location: http://localhost/Login.php"); 
      // put this ------ if($_SESSION['loginTime'] + 1000 < time()){ ------ on each page where the login is being used. 
     } 
     if (($hiredu==1) and ($hiredp==0)){ 
      //Username is correct incorrect password 
      $_SESSION['Logindets']='Your Username or Password is incorrect'; 
      header("Location: http://localhost/Login.php"); 
      exit; 
     } 

     if ($hiredu==0){ 
      $_SESSION['Logindets']='Your Username or Password is incorrect'; 
      header("Location: http://localhost/Login.php"); 
     } 

    ?> 

</html> 

所以我的問題不再是我的表單有什麼問題,但是我的php有什麼問題?

+1

旁註模具():你有'session_start();'但它不在你的第二個代碼體內。它需要在使用會話的所有文件中,*如果您還沒有這樣做。* –

+3

要求快速回答是獲得快速回答的最糟糕方式。 – moonwave99

+1

*另外,*您正在混合MySQL函數。更改'或死(mysql_error())''或死(mysqli_error())' –

回答

0

使用兩個頭總是給人一些錯誤嘗試使用上面的代碼,而不是退出()

OR

使用META標籤

<META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://localhost/Login.php"> 
+0

夥計們你會很生氣。 – Riptourtte

+1

我在標題中放了錯誤的網址 – Riptourtte

+0

我花了3天的時間一次又一次地經歷了 – Riptourtte