可能重复:
PHP 中的“警告:标头已发送”
当我将其上传到服务器时,我的 PHP 登录表单上会显示一个错误。它在我的本地主机上运行良好,但是当我将它上传到服务器时,它给了我这个错误:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 45
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 45
Warning: Cannot modify header information - headers already sent by (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 49
这是我的 PHP 代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="http://localhost/Shopping_biblioteka/css/style.css">
<title>Title</title>
</head>
<body align="center">
<div id="login">
<?php
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
$result = mysql_query("SELECT password,id FROM x9qg6_users
where username='" . $username . "'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
$test = explode(":", $row[0]);
$user_id=$row[1];
$userhash = md5($password . $test[1]);
if ($test[0] === $userhash) {
session_start();
$_SESSION['login_user'] = $user_id;
$_SESSION['username'] = $username;
$url = "biblioteka.php";
header("Location: $url");
}
} else {
echo 'Внесете ги вашите податоци во полињата!';
}
// Connects to your Database
?>
<form action="" method="POST" accept-charset="UTF-8">
Корисничко име:<br/>
<input name="username" id="username" type="text"/><br/>
Лозинка:<br/>
<input type="password" id="password" name="password"/><br/>
<input type="submit" value="Логирај се!"/>
</form>
</div>
</body>
</html>