Нужно чтоб переходило на другую страницу при авторизации.
Выходит такая вот ошибка если ставлю Location: ( Warning: Cannot modify header information - headers already sent by (output started at C:\OpenServer\domains\localhost\index.php:23) in C:\OpenServer\domains\localhost\index.php on line 39)
Код:
<?php
require "includes/database.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Login</title>
</head>
<body>
<form action="/" method="POST">
<div class="block">
<div class="card">
<div class="card-block">
<form role="form-control">
<div>
<?php
$data = $_POST;
if(isset($_SESSION['logged_user']))
{
echo '<div class="alert alert-danger" role="alert"> You already sign in </div>';
} else
if (isset($data['do_login']))
{
$errors = array();
$user = R::findOne('users', 'login = ?', array($data['login']));
if ($user)
{
if (password_verify($data['password'], $user->password))
{
$_SESSION['logged_user'] = $user;
echo '<div class="alert alert-success" role="alert"> Successfully </div>';
header('Location: dashboard.php');
} else
{
$errors[] = '<div class="alert alert-danger" role="alert"> Password is not correct </div>';
}
} else
{
$errors[] = '<div class="alert alert-danger" role="alert"> User is not found </div>';
}
if ( ! empty($errors))
{
echo array_shift($errors);
}
}
?>
</div>
<div class="input-group">
<span class="input-group-addon"><span class="fa fa-user"></span></span>
<input type="text" class="form-control" placeholder="Username" name="login" value="<?php echo @$data['login']; ?>" required />
</div>
<div class="input-group">
<span class="input-group-addon"><span class="fa fa-lock"></span></span>
<input type="password" class="form-control" placeholder="Password" name="password" value="<?php echo @$data['password']; ?>" required />
</div>
<div>
<button type="sumbit" class="btn btn-outline-danger btn-block" name="do_login">
<span class="btn-label"></span>Sign in</button>
</div>
</form>
</div>
<div class="card-footer">
<a href="/signup.php" class="btn btn-outline-primary btn-block">Create account</a>
</div>
</div>
</div>
</form>
</body>
</html>