Header that does not want to work [duplicated]

0

I want to redirect to a web page with header in php but it throws me an error that says something like:

PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/sitio/public_html/includeses/analyticstracking.php:1)

and then mention the line number where I have the header defined

$variableApasar = 200;
header('Location: pagina.php?var=' . base64_encode($variableApasar));

PHP what's wrong with you?

    
asked by MNibor 18.11.2017 в 17:19
source

1 answer

2

PHP functions that send or modify HTTP headers must be executed before the requested page has been sent to the user. Otherwise, the following error will occur:

Warning: Cannot modify header information - headers already sent
(output started at file:line)

The PHP functions that modify the HTTP headers are the following:

header() / header_remove()
session_start() / session_regenerate_id()
setcookie() / setrawcookie()

And the ways to start sending content to the user before these functions are executed can be intentional or unintentional:

Intentional:

  • Show information with print or echo
  • Dump the content of variables with var_dump()
  • Use any of these functions: printf(), trigger_error(), vprintf(), ob_flush(), readfile() o passthru() .
  • Add HTML code before the%% open% tag

Unintentional:

  • Add some blank space before <?php or after <?php
  • The BOM (Byte Order Mark) of UTF-8
  • Error messages or notices produced previously
answered by 18.11.2017 / 17:26
source