Jump to content
  • 0

Работа с куками


Kisa1993
 Share

Question

index.php


<?php
//проверка на наличие cookie
if (!isset($_COOKIE['mycook']))
{
setcookie('mycook','теперь ты знаешь как работает cookie',time()+15);
// редирект на cookie.php
header("Location: cookie.php");
}
else echo"ты уже знаешь как работает механизм cookie";


?>

cookie.php


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<title>Результат</title>
</head>

<body>
<?php
echo $_COOKIE['mycook'];
?>

</body>
</html>

После вызова index.php выходят сообщения:

Warning: Cannot modify header information - headers already sent by (output started at Z:\home\test1.ru\www\dark\index.php:10) in Z:\home\test1.ru\www\dark\index.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at Z:\home\test1.ru\www\dark\index.php:10) in Z:\home\test1.ru\www\dark\index.php on line 16

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

эм.. rus, чего здесь гадать то?

Warning: Cannot modify header information - headers already sent by (output started at Z:\home\test1.ru\www\dark\index.php:10) in Z:\home\test1.ru\www\dark\index.php on line 14

заголовки были отосланы, так как output started at Z:\home\test1.ru\www\dark\index.php:10

Link to comment
Share on other sites

  • 0

эм.. rus, чего здесь гадать то?

Warning: Cannot modify header information - headers already sent by (output started at Z:\home\test1.ru\www\dark\index.php:10) in Z:\home\test1.ru\www\dark\index.php on line 14

заголовки были отосланы, так как output started at Z:\home\test1.ru\www\dark\index.php:10

я не гадаю, я лишь сказал что конкретно этот код - рабочий.

Link to comment
Share on other sites

  • 0

инклюд index.php и кода с куки должен быть выше всего где что то выводится, если есть хотя бы одно echo до кода с куки или редиректа (header("Location) должна быть ошибка, пхп такой

Edited by rogihor
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy