Good day.
I have a script which after a user signs in sends it to the control panel of their account through a link that has to be clicked, everything works great, but I think it would be better to automatically redirect to the control panel and so not having to click on the mentioned link, the problem is that it does not redirect with header, the following error comes out
Warning: Can not modify header information - headers already sent by (output started at /home2/gabriel/tecflucol.com/sistema/PHP/checklogin.php:4) in /home2/softwareiii.com/sistema/PHP/checklogin.php on line 26
How could I solve it and redirect the page automatically?
Here's the code:
<?php
session_start();
?>
<?php
include('../PHP/conectar.php');
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM 'usuarios' WHERE 'usuario'='$username';";
$result = $conexion->query($sql);
if ($result->num_rows > 0)
{
$row = $result->fetch_array(MYSQLI_ASSOC);
}
if (password_verify($password, $row['contrasena']))
{
$_SESSION['loggedin'] = true;
$_SESSION['usuario'] = $username;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (5 * 800000);
//rediriguir automanticamente
header('Location: panel_de_control.php');
//estas dos lineas funcionan bien pero la idea es suprimirlas
//echo "Bienvenido(a)! ".$_SESSION['usuario'];
//echo "<br><br><a href=panel_de_control.php>PANEL DE CONTROL</a>";
}
else
{
echo "Usuario o contraseña estan incorrectos.";
echo "<br><a href='../login.html'>Volver a Intentarlo</a>";
}
mysqli_close($conexion);
?>