Good day!

Faced with the fact that browsers - Safari, Firefox, YandexBrowser, do not store cookies for a very long time. What is it connected with? Chrome, for example, clearly stores, for a long time as indicated in the code. All the others are different, some people lose the cook in half an hour someone else in a day.

Here is the code for how I do it:

header("Content-Type: text/html; charset=UTF-8"); session_set_cookie_params('3600'); ini_set ("session.use_trans_sid", true); session_start(); ini_set ("display_errors", true); date_default_timezone_set('Europe/Moscow'); 

.... ....

I save cookies:

 setcookie ("param1", $value1, time() + (3600*24*365), "/", "scroll"); setcookie ("param2", $value2, time() + (3600*24*365), "/", "scroll"); 

It seems to be doing everything right.

Thank you very much!

Ps.

Now everything is on the turn, saved in firefox, safari, but completely refuses to save cookies in chrome and Yandex Browser

Here is an example of what I am doing (I tried different versions)

  header("Content-Type: text/html; charset=UTF-8"); session_set_cookie_params(3600); ini_set ("session.use_trans_sid", '1'); my_session_start(); ini_set ("display_errors", '1'); date_default_timezone_set('Europe/Moscow'); function my_session_start() { if (ini_get('session.use_cookies') && isset($_COOKIE['PHPSESSID'])) { $sessid = $_COOKIE['PHPSESSID']; } elseif (!ini_get('session.use_only_cookies') && isset($_GET['PHPSESSID'])) { $sessid = $_GET['PHPSESSID']; } else { session_start(); return false; } if (!preg_match('/^[a-z0-9]{32}$/', $sessid)) { return false; } session_start(); return true; } 

Then I save the cookies as follows:

 $path = "/"; $domen = "localhost"; setcookie ("login", $row['email'], time() + (3600*24*365), $path, $domen); 

They simply do not appear in the list of cookies. But the session norms, is saved.

Then I tried to remove $ path and $ domen, started saving cookies. But for example, the session does not save in safar, Yandex browser and firefox, but in chrome it also saves the session and stores cookies. :(

  • First of all, it is worth looking at what expires value actually gets into the browser (that is, that the browser itself will report received cookies). - user6550
  • you have "scroll" specified as a domain. maybe this is the problem? in fact, modern browsers almost perfectly meet standards. Ato there is a difference in how they react to errors. - artoodetoo

2 answers 2

Carefully check how your data correspond to the description of the parameters of functions. For example, it is not clear why you are writing "3600" where an integer value is expected, true where a string is needed or the value "scroll" as a domain.
The problem you described may not be directly from these things, but you probably didn't bring all the code. Be careful!

  • I already do not know what's the matter. Isprail. now my cookies are perfectly written in Firefox and Safari, but they completely stopped writing in Yandex.Browser and Chrome. And the session is saved and the cookies are not written. I do not know how to give an example. :( - inkognitum

The author himself set the parameter

 session_set_cookie_params('3600'); 

Which clearly indicates the life of a cook in one hour.

UPD: Works great in all browsers.

 setcookie('my_cookie', 'my_value', strtotime('+365 days'), '/'); 

UPD: Look carefully at your code (the error is obvious).

PS I waited for at least a comment to the negative feedback on the answer :)