setcookie
doesn't work when I use with thinkphp framework. just $a = setcookie('a','a');
no path no domain. var_dump($a)
returns bool(false);
no output before this, and no warning.
but when I didn't use the framework , it works.
The documentation for setcookie()
says that "If output exists prior to calling this function, setcookie() will fail and return FALSE." So be sure to put setcookie()
before any statements that might write to STDOUT.
When this happens, PHP will log a warning in your error log: "PHP Warning: Cannot modify header information - headers already sent by..." So check your error log file.
You must set cookies before sending any data. Before any echo and so on. So framework maybe have its own cookie handler. Check its documentation.
Or you can use extension: