Hello! Tell setCookie , please, when setting the cookie lifetime, for example, with the setCookie function

 setСookie( $inKey , '345' , time()+3600 ); 

How is it checked that the lifetime has not yet expired? Do you use time on a client machine or server?

    3 answers 3

    time() display a timestamp from the beginning of the Unix era, i.e. (The Unix Epoch, January 1, 1970, 00:00:00 GMT) to the current time. and it is in no way tied to the server or user time.

    • No, I didn’t ask about the time function, but about how it checks whether cookies are outdated - masha2
    • one
      Well, as a server .... it controls on its side. if the client has a cookie, then the browser controls how long cookies are being tweaked ... it doesn’t matter what time zone the user has or the server has. - thunder
    • those. no matter what time zone the server and client are in, if you specify that the cookie should live for half an hour, then for all users it will live for half an hour? - masha2
    • Yes, that is why it is better to use time () in all time data, i.e. unix time stamp. - thunder
    • If the user’s clock is half an hour behind, then he will not be able to deliver a cookie for half an hour. And the time zone is not important, since it is sent in the expires parameter. - Indifferently

    if(isset($_COOKIE['some_cookie'])) { /* ... */ }

    if(!isset($_COOKIE['some_cookie'])) { /* ... */ }

    • umm, apparently this was the answer the girl was waiting for, something I thought the wrong way))) - thunder
    • one
      thanks, but I'm not talking about that at all) - masha2

    The browser simply deletes the cookie that has expired (during url) and does not send it to the server, so the server does not see the cookie and everyone is happy.

    In short, the answer is - it is not checked in any way - either there is a cookie or there is none. the client does not even send the server any data on the cookie, except for its name and value.

    However, data on the life of cookies can be obtained on the client side in js.