In general, the code is the simplest

setcookie('test', 'test', time()+86400, '/'); 

Nothing is written to cookies. What could be the problem?

  • Do you have no output to the browser before calling setcookie? - MDJHD
  • Good day! Most likely they are not written for one of two reasons: it is described here . - Kostya

1 answer 1

Possible problems:

  1. Cookies are disabled for the user
  2. Before setting the cookie, you had output to the browser (even if a space or line feed)
  3. If you are looking for cookies in $ _COOKIE in the same script where you installed it, you will not find it. Only the next time you run the script

      if(setcookie('test', 'test', time()+86400, '/')) echo "Кука установлен"; else echo "Кука не установлен"; 

But if setcookie () returns true - this does not mean that it will appear at the client, because he could turn off the reception of cookies. Better read about the session.

  • Receiving cookies is enabled by the user, but they are still not accepted. - vitagame
  • @vitagame, try to look at returned headers (via console / chrome extension or using curl). There should be a set cookie: trawling. - etki
  • Well, what is the value returned by setcookie () checked? - MDJHD
  • Checked. Cookies are not installed. - vitagame
  • Can you call the following code from another script and show us the output? <? php $ url = 'Full URL to the page that should set cookies'; print_r (get_headers ($ url)); ?> - MDJHD