Answer the question
In order to leave comments, you need to log in
Cookies in PHP how?
There was a problem beaten to holes: cookies are not saved. But she's acting very strange.
In general, the first version of the engine saved some data to a file on the server, and gave the user cookies. At the same time, the HTML code was before the PHP code, and the setting of cookies was successful:
<!DOCTYPE html>
<html>
...
<?php
...
// тут какой-то код
setcookie ("authentic", $authentic);
PHP Warning: Cannot modify header information - headers already sent by (output started at /путь к файлу:12) in /путь к тому же файлу on line 275
<!DOCTYPE html>
<html>
...
<?php
include("./database.php"); // файл ЧИСТ, там НЕТ вывода вообще, только функции для базы данных, в начале BOM тоже НЕТ
...
setcookie ("authentic");
?>
Answer the question
In order to leave comments, you need to log in
Due to buffering, no data was sent before the cookie was set. And now there is more data, PHP sends it before the setcookie is executed.
Who does not believe that this is possible, run the script:
Hello world!
<?php setcookie('test', 'test') ?>
<?php for ($i = 1; $i < 500; ++$i) echo 'Hello world!
'; ?>
<?php setcookie('test', 'test') ?>
Warning: Cannot modify header information - headers already sent
1) Learn the basics of the HTTP protocol, in particular, what are response headers
2) Read about output buffering
In theory, neither the first nor the second scheme should work at all. Cookies must be set before any output starts. MySQL has nothing to do with it.
So you connect database.php
after the markup begins. It is displayed before setting cookies.
Cookies are passed in headers, this is the HTTP standard. If you started the output, then the headers are already gone, and they (the headers) cannot be sent again. Here is your problem. Start outputting data after running PHP.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question