2011-12-14 99 views
1

我有一個使用Dreamweaver CS4創建的login.php頁面。 在表單中輸入用戶名和密碼後,頁面會自動重新加載而不會重定向到所需的位置。 網址現有的網站:http://www.decoraflooringstore.com 登錄頁面點擊客戶端登錄 後打開下面是PHP代碼: 感謝任何輸入日誌php頁面不重定向

<?php require_once('Connections/test.php'); ?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
     case "long": 
     case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
     case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
     case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
     case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

mysql_select_db($database_test, $test); 
$query_Recordset1 = "SELECT `user`.`user name`, `user`.password FROM `user`"; 
$Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 
?> 
<?php 
// *** Validate request to login to this site. 
if (!isset($_SESSION)) { 
    session_start(); 
} 

$loginFormAction = $_SERVER['PHP_SELF']; 
if (isset($_GET['accesscheck'])) { 
    $_SESSION['PrevUrl'] = $_GET['accesscheck']; 
} 

if (isset($_POST['username'])) { 
    $loginUsername=$_POST['username']; 
    $password=$_POST['username']; 
    $MM_fldUserAuthorization = ""; 
    $MM_redirectLoginSuccess = "success login.php"; 
    $MM_redirectLoginFailed = "failed login.php"; 
    $MM_redirecttoReferrer = false; 
    mysql_select_db($database_test, $test); 

    $LoginRS__query=sprintf("SELECT `user name`, password FROM `user` WHERE `user  name`=%s AND password=%s", 
     GetSQLValueString($loginUsername, "-1"), GetSQLValueString($password, "text")); 

    $LoginRS = mysql_query($LoginRS__query, $test) or die(mysql_error()); 
    $loginFoundUser = mysql_num_rows($LoginRS); 
    if ($loginFoundUser) { 
     $loginStrGroup = ""; 

     //declare two session variables and assign them 
     $_SESSION['MM_Username'] = $loginUsername; 
     $_SESSION['MM_UserGroup'] = $loginStrGroup;   

     if (isset($_SESSION['PrevUrl']) && false) { 
     $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; 
     } 
     header("Location: " . $MM_redirectLoginSuccess); 
    } 
    else { 
     header("Location: ". $MM_redirectLoginFailed); 
    } 
} 
?> 
<table width="500" border="0" align="center"> 
    <tr> 
     <td><table width="400" border="0" align="center"> 
     <tr> 
      <td>Username</td> 
      <td><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>"> 
       <label> 
       <input type="text" name="username" id="username" /> 
       </label> 
      </form></td> 
      </tr> 
      <tr> 
      <td>Password</td> 
      <td><form id="form2" name="form2" method="post" action=""> 
       <label> 
        <input type="text" name="password" id="password" /> 
       </label> 
      </form></td> 
      </tr> 
      <tr> 
      <td>&nbsp;</td> 
      <td><form id="form3" name="form3" method="post" action=""> 
       <label> 
       <input type="submit" name="login" id="login" value="Login" /> 
       </label> 
      </form></td> 
      </tr> 
     </table></td> 
    </tr> 
</table> 
<?php 
mysql_free_result($Recordset1); 
?> 
+0

建議:你不需要打開和關閉一個php標籤每個功能喲有這是NASTY) – 2013-10-04 02:18:14

回答

0

爲了能夠重定向,必須避免將以前的內容。否則,您將收到消息「標題已發送」。

命令session_start()將發送標題,不允許進一步重定向。

避免也有多個打開和關閉php標籤。您要在結束標記和下一個開始標記之間發送換行符。這也會導致標題被髮送,不允許重定向按預期工作。

0

使用isset函數檢查用戶名和密碼。和我在條件語句中 如果passsword正確 header(「location:index.php」); else header(「location:something.php」); 它是什麼,如果你的信息是有效的,它會重定向到index.php,如果不是有效的,它將重定向到something.php