Error logging into php site [duplicate]

0

I have this code to log in to my site:

session_start();
ob_start();
define('URL', 'http://www.pardaldobico.com.br/');

define('CONTROLER', 'home');
define('METODO', 'index');
header('Content-Type: text/html; charset=utf-8');

But the server is experiencing this error:

PHP Warning: session_start (): can not send session cache limiter - headers already sent (/ started / line 2

PHP Warning: Can not modify header information - headers already sent by / p>

Can anyone help me?

    
asked by anonymous 04.08.2017 / 16:16

2 answers

2

It has to be this way

 <?php
 session_start();
 ob_start();
 ...............
 ...............

So you can

 <?php

 session_start();
 ob_start();
 ...............
 ...............

So you can not

 <?php // Espaço antes da tag PHP | Envio do header
session_start();
?>

Not so

 <?php
 echo 'Olá Francene Arnaut'; // Aqui está o header, sendo enviado ao usuário do site 
 através do comando echo
 session_start(); // Início de sessão depois do envio do header = Erro
 ?>
  

Summary

  • Do not create and / or set a session after sending an echo;
  • All code that works with sessions, cookies, redirects, and (headers) encryption must be defined, created, sent, and modified before HTML.

Error - Can not modify header information

    
04.08.2017 / 18:29
0

Francene, check for blanks before opening your php. If this message is appearing indicates that the response header has already been sent to the browser, and therefore it is not possible to attach the session data to the header. Usually this happens when you have a print output in your code or a blank space in your php before opening the <?php script. Make sure you always log on to the top of your script.

    
04.08.2017 / 16:49