我正在制作一个简单的注册和登录页面,登录后您将在其中重定向到index.php。注册工作正常,但登录后出现此错误。 “警告:无法修改标头信息-标头已由第27行的/login.php中的(发送自/login.php:9的输出发送)”
当我在xampp服务器上创建此网站时,它运行良好,但是当我将其联机时,会出现此错误:(
我已经在Google查了几个小时,而我遇到的每个解决方案都没有用。我知道有很多关于此错误的问题,但我花了一整天的时间来解决这个问题,但我现在想放弃了。请帮助我
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
// If form submitted, insert values into the database.
if (isset($_POST['username'])){
// removes backslashes
$username = stripslashes($_REQUEST['username']);
//escapes special characters in a string
$username = mysqli_real_escape_string($con,$username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
//Checking is user existing in the database or not
$query = "SELECT * FROM `users` WHERE username='$username'
and password='".md5($password)."'";
$result = mysqli_query($con,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1){
$_SESSION['username'] = $username;
// redirect
header("Location: index.php"); // this is line 27
}else{
echo "<div class='form'>
<h3>Username/password is incorrect.</h3>
<br/>Click here to <a href='login.php'>Login</a></div>";
}
}else{
?>
<div class="form">
<h1>Log In</h1>
<form action="" method="post" name="login">
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<input name="submit" type="submit" value="Login" />
</form>
<p>Not registered yet? <a href='registration.php'>Register Here</a></p>
</div>
<?php } ?>
</body>
</html>