Error to log in to php site

Asked

Viewed 941 times

0

I have this code to log in to my website:

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 showing this error:

PHP Warning: session_start(): Cannot send Session cache Limiter - headers already sent (output Started at /home/pardaldobicocom/public_html/index.php:14) in /home/pardaldobicocom/public_html/config/Config.php on line 2

PHP Warning: Cannot Modify header information - headers already sent by (output Started at /home/pardaldobicocom/public_html/index.php:14) in /home/pardaldobicocom/public_html/config/Config.php on line 8

Can someone help me?

  • The second message has a topic on it : https://answall.com/questions/4251/erro-cannot-modify-header-information

  • Hello Francene Arnaut, welcome! Read this post https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

2 answers

2

It has to be like this

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

So you can

 <?php

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

So you can’t

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

Even 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;
  • Every code that works with sessions, cookies, redirects and encryption (headers) must be defined, created, sent and modified before HTML.

Error - Cannot Modify header information

  • Leo, where you are "so you can’t", can rather because spaces within the opening delimiter of "<? php" are not interpreted as header output. What cannot be a space before the opening of "<? php". Anyway by the example +1

  • @Rafaelsalomão, oops, missed something in space, thanks!

  • Now yes perfect! So can ! = P

  • hahahaha, thank you :)

0

Francene, check whitespace before opening your php. If this message is showing up indicates that the response header has already been sent to the browser, and therefore it is not possible to attach 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 script <?php. Make sure to sign in always at the top of your script.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.