Warning: session_start (): Can not send session cookie - headers already sent

1

Error when trying to enter I explain in localhost it works fine but when uploading it to some server it marks this error

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /storage/ssd3/893/822893/public_html/index.php:33) in /storage/ssd3/893/822893/public_html/php/login.php on line 11

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /storage/ssd3/893/822893/public_html/index.php:33) in /storage/ssd3/893/822893/public_html/php/login.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd3/893/822893/public_html/index.php:33) in /storage/ssd3/893/822893/public_html/php/login.php on line 15

Look for there that session_start should be at the start after the <?php

tag
<?php
session_start();

but it remains the same also look that it was for the spaces in white good join the lines without leaving lines and remains the same

here is my original code

<?php



    $correo=$_POST['correo'];
    $clave=md5($_POST['clave']);
    require_once('Conexion.php');
    $conn = Conectar();

    $stmt = $conn->prepare("SELECT  id_usuario, nombre, apellido, correo, p.id_perfil, perfil FROM usuario u INNER JOIN perfil p ON p.id_perfil=u.id_perfil WHERE u.correo=:correo AND u.clave=:clave");
    $stmt->bindParam(':correo',$correo);
    $stmt->bindParam(':clave',$clave);
    $stmt->execute();



    if($stmt->rowCount()==1){
        session_start();
        $fila=$stmt->fetch();
        $_SESSION['idperfil']=$fila['id_perfil'];
        if($fila['id_perfil']==1)
            {header("Location: administrador/index.php");}
        if($fila['id_perfil']==2)
            {header("Location: aprendiz/index.php");}
        if($fila['id_perfil']==3)
            {header("Location: root/index.php");}
    }
    else{
         echo "<font color='red'>Datos No Validos</font>";
    }
?>

I hope you can help me and thank you

    
asked by Zen 05.09.2017 в 19:20
source

1 answer

1

According to the PHP documentation :

  

To use session based on cookies, session_start() must be   call before printing anything in the browser.

You must check that there is absolutely no type of output ( echo, print... ) or HTML code before session_start();

And that is not only referring to the script in question, but you should take it into account especially when you concatenate files using include or require . The error message indicates that the files login.php e index.php are intervening. If for example you include HTML code in login.php or you take something out of the screen and then use session_start() in index.php you will have this kind of errors.

    
answered by 05.09.2017 в 19:55