S
S
Stepan2014-10-29 12:45:42
PHP
Stepan, 2014-10-29 12:45:42

What are some reasons why a cookie may not be set?

I check if cookies are being installed - says no.

if (SetCookie("Test","Value")){
echo "<h3>Cookies успешно установлены!</h3>";
}else{echo "shit";};

gives out shit
What reasons of such behavior can be?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stepan, 2014-10-29
@ykppon

Thanks to all. I'm a moron!

A
Alexander Sydorenko, 2014-10-29
@San40

Cookies must be set before anything is rendered to the browser. That is, your code must be at the very top of the script for it to work correctly. In other words, there should not be any echo, print_r, var_dump calls before these lines.

F
FanatPHP, 2014-10-29
@FanatPHP

I'll just leave this here:
Nothing works! What to do???
The reasons must be learned not from passers-by on the street, but from their own system. Only she can answer accurately, and not guess on the coffee grounds.
Update.
It's clear from the comments on another question that the author needs to first understand that a cookie is an HTTP header, and how HTTP headers differ from variables in a program.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question