-3
我試圖讓一個登錄名和PHP中註冊系統和我不斷收到一個錯誤代碼時,我使用header("Location: index.php")
,這是錯誤我得到:標題位置PHP不工作?
警告:不能更改頭信息 - 頭已經發出(輸出開始於C:\ Users \ Omg \ Desktop \ XAMPP \ htdocs \ Websites \ Social-Network \ register.php:43)在C:\ Users \ Omg \ Desktop \ XAMPP \ htdocs \ Websites \ Social-Network \ register .PHP上線141 的index.php
這裏是我的PHP代碼:
if(!empty($_POST)) {
if(empty($_POST['username'])){
echo("Please enter a Display Name<br />");
}
if(empty($_POST['password'])){
echo("Please enter a password<br />");
}
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
echo("Please enter a valid email address<br />");
}
$query = "
SELECT
1
FROM users
WHERE
username = :username
";
$query_params = array(
':username' => $_POST['username']
);
try{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex) {
die("Failed to run query: ");
}
$row = $stmt->fetch();
if($row){
echo("This name is taken by another person<br />");
}
$query = "
SELECT
1
FROM users
WHERE
email = :email
";
$query_params = array(
':email' => $_POST['email']
);
try{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex) {
echo("Failed to run query: ");
}
$row = $stmt->fetch();
if($row){
echo("This email is already taken!<br />");
}
$query = "
INSERT INTO users (
username,
password,
salt,
email
) VALUES (
:username,
:password,
:salt,
:email
)
";
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
$password = hash('sha256', $_POST['password'] . $salt);
for($round = 0; $round < 65536; $round++) {
$password = hash('sha256', $password . $salt);
}
$query_params = array(
':username' => $_POST['username'],
':password' => $password,
':salt' => $salt,
':email' => $_POST['email']
);
try{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}catch(PDOException $ex) {
echo("Failed to run query: ");
}
header("Location: index.php");
die("index.php");
}
我正在使用一個網站來幫助我,我也有一個數據庫連接,但它沒有提到。任何幫助,將不勝感激。
好 - 看看錯誤信息,以及它試圖告訴你什麼:在發送內容後,**不能**發送標題**! –
我甚至在所有代碼之前發送它,但仍然出現錯誤 –
以下是網站:[http://forums.devshed.com/php-faqs-stickies-167/program-basic-secure-login-system-使用-php-mysql-891201.html](鏈接) –