2012-10-22 76 views
0

我有一個登錄腳本,當窗體重定向它只是顯示一個空白屏幕,任何想法?我對PHP很陌生,所以對腳本的任何評論都會很棒。登錄腳本給空白屏幕

非常感謝您的幫助!

<?php 
session_start(); //must call session_start before using any $_SESSION variables 
$username = $_POST['username']; 
$password = $_POST['password']; 
//connect to the database here 

require_once('../Connections/PropSuite.php'); 
mysql_select_db($database_PropSuite, $PropSuite); 

$username = mysql_real_escape_string($username); 
$query = "SELECT password, salt 
     FROM users 
     WHERE username = '$username';"; 
$result = mysql_query($query); 
if(mysql_num_rows($result) < 1) //no such user exists 
{ 
    header('Location: index.php'); 
    die(); 
} 
$userData = mysql_fetch_array($result, MYSQL_ASSOC); 
$hash = hash('sha256', $userData['salt'] . hash('sha256', $password)); 
if($hash != $userData['password']) //incorrect password 
{ 
    header('Location: index.php'); 
    die(); 
} 
else 
{ 
    validateUser(); //sets the session data for this user 
} 
//redirect to another page or display "login success" message 


?> 
+0

如果登錄的數據實際上是正確的,會發生什麼?在這種情況下,我看不到重定向(除非它在validateUser中) – mboldt

+0

您是否檢查過日誌? –

+0

哦,很多人會告訴你使用PDO :-) http://us.php.net/pdo – mboldt

回答

0

我認爲你錯過了重定向,除非你在validateUser()函數中有它。 如果沒有,你可以做兩種:

else 
{ 
    validateUser(); //sets the session data for this user 
} 
//redirect to another page or display "login success" message 
header('Location: your-desired-login-location.php'); 
die(); 
?> 

或..

else 
{ 
    validateUser(); //sets the session data for this user 
    header('Location: your-desired-login-location.php'); 
    die(); 
} 
//redirect to another page or display "login success" message 

?> 
0

您可能會在代碼中解析錯誤並關閉錯誤報告。

解決方案:

把這個放在你的標題中,看到錯誤,改正它們。完成後刪除 - 這是一個非生產環境。

error_reporting(E_ALL & ~E_NOTICE); 
ini_set('display_errors', TRUE); 
ini_set('display_startup_errors', TRUE);