header (location) redicect after some time [duplicate]

0

I have a file that is like this:

    <?php
    session_start();
    include("template/head.php");
    include("template/header.php");
    include ("inc/functions.php");
?>
<div class="content">
<?php
    $password = encripta_password($_POST['loginpass']);
    include ("db_files/db.php");
    $strSQL = "SELECT * FROM usuarios where email = '".$_POST['loginmail']."'";
    $query = mysqli_query($db, $strSQL);
    while($result = mysqli_fetch_array($query)){
        if ($password == $result['password'] && $_POST['loginmail'] == $result['email']){
            echo "<br><center><h4>Has iniciado sesión, serás redirigido en 5 segundos</h4></center>";
            $_SESSION['user']=$result['email'];
            header( "refresh:5;url=index.php" );
        }else {
            echo "error";
        }
    }

    mysqli_close($db);
?>
</div>
<?php
    include("template/footer.php");
?>

But when I come from my form, to the page with the code mentioned above I get this error:

  

Warning: Can not modify header information - headers already sent by   (output started at   C: \ xampp \ htdocs \ oneplayer_git \ template \ header.php: 57) in   C: \ xampp \ htdocs \ oneplayer_git \ logincheck.php on line 17

    
asked by Pavlo B. 26.10.2016 в 13:30
source

2 answers

2

Try to put at the beginning of the file:

<?php
ob_start();
?>

and at the end of it:

<?php
ob_end_flush();
?>

Come on, it would be:

<?php
ob_start();
session_start();
include("template/head.php");
include("template/header.php");
include ("inc/functions.php");
?>
    <div class="content">
        <?php
$password = encripta_password($_POST['loginpass']);
include ("db_files/db.php");
$strSQL = "SELECT * FROM usuarios where email = '".$_POST['loginmail']."'";
$query = mysqli_query($db, $strSQL);
while($result = mysqli_fetch_array($query)){
if ($password == $result['password'] && $_POST['loginmail'] == $result['email']){
echo "<br><center><h4>Has iniciado sesión, serás redirigido en 5 segundos</h4></center>";
$_SESSION['user']=$result['email'];
header( "refresh:5;url=index.php" );
}else {
echo "error";
}
}

mysqli_close($db);
?>
    </div>
    <?php
include("template/footer.php");
ob_end_flush();
?>
    
answered by 26.10.2016 / 13:54
source
0

Try this:

header( "refresh:10; url=ruta.php" );

The refresh time is in seconds.

    
answered by 26.10.2016 в 15:22