2012-10-22 77 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);