Возникла ошибка Warning: Cannot modify header information - headers already sent by(путь до файла). Хочу сделать регистрацию на сайте, но не могу. Код самого файла прикреплю.
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<title>Главная</title>
</head>
<body>
<?php
require "blocks/header.php";
require "connection.php";
if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
$query = "INSERT INTO `users` (`username`, `password`, `reg_date`) VALUES ('$username', '$password', 323)";
$result = mysqli_query($connection, $query);
if($result && ($_POST['username'])!='' && ($_POST['password'])!='') {
$smsg = 'Регистрация прошла успешно';
} else{
$fmsg = 'Ошибка';
}
}
if($smsg){
setcookie('user', 'Да', time() + 7200, '/');
header('Location: /');
}
?>
<div class="container">
<form class="form-signin" method="post">
<h2>Регистрация</h2>
<?php if(isset($smsg)){?> <div class="alert alert-success" role='alert'> <?php echo $smsg;?> </div> <?php } ?>
<?php if(isset($fmsg)){?> <div class="alert alert-danger" role='alert'> <?php echo $fmsg;?> </div> <?php } ?>
<input type="text" class="form-control" name="username" placeholder="Логин">
<input type="password" class="form-control" name="password" placeholder="Пароль">
<button class="btn btn-lg btn-primary btn-block" type="submit">Зарегистрироваться</button>
</form>
</div>
<?php require "blocks/footer.php" ?>
</body>
</html>
Код header.php
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
<h5 class="my-0 mr-md-auto font-weight-normal">Сашка corp.</h5>
<nav class="my-2 my-md-0 mr-md-3">
<a class="p-2 text-dark" href="/">Главная</a>
<a class="p-2 text-dark" href="../about.php">Контакты</a>
</nav>
<?php if ($_COOKIE['user'] == 'Да'): ?>
<a class="btn btn-outline-primary" href="/profile.php">Личный кабинет</a>
<?php else: ?>
<a class="btn btn-outline-primary" href="/auth.php">Войти</a>
<a class="btn btn-outline-primary ml-2" href="/registration.php">Зарегистрироваться</a>
<?php endif; ?>
</div>
Код connection.php
<?php
$connection = mysqli_connect('localhost', 'root','');
$select_db = mysqli_select_db($connection, 'dynweb');
?>