I
I
Ibishka2020-05-15 19:47:30
PHP
Ibishka, 2020-05-15 19:47:30

Error when redirecting to another page?

5ebec92bdab51456430389.png
5ebec9386902a091333773.png
Error when logging in

Warning: Cannot modify header information - headers already sent by (output started at C:\OpenServer\domains\localhost\login.php:2) in C:\OpenServer\domains\localhost\login.php on line 29

As soon as I insert a piece of code for redirection on line 1 or 2 in the editor, there is no error, but somewhere else if I insert it, then an error.
piece of code
header('Location: /');
exit();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2020-05-15
@Ibishka

If you want to work with headers, then you cannot place bare html with php code inclusions, the log will be clogged with warnings.
When executing a php file at the beginning, it should be silent like a fish, if the logic of work provides for a choice - work first with headers, and then display content, or simply output content (via print, echo, etc.).
That is, headers must fire first, any echo between header() will break the order.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question