我想添加一個簡單的登錄到一個網站,並使其在我的本地主機XAMPP服務器上完美工作,但現在當上傳到我的網站時,我能夠註冊新用戶,但是當我去登錄頁面只是空白。php登錄工作在XAMPP,但不是網絡服務器?
<?php
$error = '';
if (isset($_POST['login'])) {
session_start();
$username = trim($_POST['username']);
$password = trim($_POST['pwd']);
// location to redirect on success
$redirect = './adminArea_db.php';
require_once('./includes/authenticate_pdo.inc.php');
}
?>
<!DOCTYPE HTML>
<html>
<link href="css/screen.css" rel="stylesheet" media="screen" />
<meta charset="utf-8">
<title>Login</title>
</head>
<body>
<div id="main">
<?php
if ($error) {
echo "<p>$error</p>";
} elseif (isset($_GET['expired'])) {
?>
<p>Your session has expired. Please log in again.</p>
<?php } ?>
<form id="form1" method="post" action="">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="">
</p>
<p>
<label for="pwd">Password:</label>
<input type="password" name="pwd" id="pwd">
</p>
<p>
<input name="login" type="submit" id="login" value="Log in">
</p>
</form>
</div>
</body>
</html>
任何想法?
在我的error_log中發現了一些錯誤,不確定是否有用?
[11-Feb-2014 20:48:52 Europe/London] PHP Warning: session_start() [<ahref='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/georgepa/public_html/login_db.php:2) in /home/georgepa/public_html/login_db.php on line 6
[11-Feb-2014 20:48:52 Europe/London] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/georgepa/public_html/login_db.php:2) in /home/georgepa/public_html/login_db.php on line 6
[11-Feb-2014 20:48:52 Europe/London] PHP Warning: session_regenerate_id() [<a href='function.session-regenerate-id'>function.session-regenerate-id</a>]: Cannot regenerate session id - headers already sent in /home/georgepa/public_html/includes/authenticate_pdo.inc.php on line 28
[11-Feb-2014 20:48:52 Europe/London] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/georgepa/public_html/login_db.php:2) in /home/georgepa/public_html/includes/authenticate_pdo.inc.php on line 29
認爲這是我的authenticate_pdo.inc.php文件有問題...
<?php
require_once('./includes/connection.inc.php');
$conn = dbConnect();
// get the username's details from the database
$sql = 'SELECT salt, pwd FROM users WHERE username = :username';
// prepare statement
$stmt = $conn->prepare($sql);
// bind the input parameter
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
// bind the result, using a new variable for the password
$stmt->bindColumn(1, $salt);
$stmt->bindColumn(2, $storedPwd);
try{
$stmt->execute();
$stmt->fetch();
}catch(PDOException $e){
exit('problem reading from table users'.$e->getMessage());
}
dbClose($conn) ;
// encrypt the submitted password with the salt and compare with stored password
if (sha1($password . $salt) == $storedPwd) {
$_SESSION['authenticated'] = 'admin'; // role of authenticated user
$_SESSION['username']=$username;
// get the time the session started
$_SESSION['start'] = time();
session_regenerate_id();
header("Location: $redirect");
exit;
} else {
// if no match, prepare error message
$error = 'Invalid username or password';
}
?>
首先打開錯誤報告。 – Hast
如何打開錯誤報告? – user3010383
看這裏:http://stackoverflow.com/questions/6575482/how-do-i-enable-error-reporting-in-php和http://stackoverflow.com/questions/6127980/enabling-error-display- in-php-via-htaccess- – Hast