how to kill the session cookie after a period of time in php

841

if I define the session.cookie_lifetime to be zero so the cookie will only be killed after the browser is closed. but if I want to sent a max time which after that even if the browser was not closed the session will end anyway???? integer

510

Answer

Solution:

This makes the cookie to be expired in one hour.

setcookie("TestCookie", $value, time()+3600);

More about setting cookie is at here.

513

Answer

Solution:

Assign value forsession.cookie_lifetime in PHP ini file.

session.cookie_lifetime=300 for 5 mins

421

Answer

Solution:

Normal Cookie From php.net The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).

That will give a nice long cookie.

Session Based Cookie php.net link [http://www.php.net/manual/en/function.session-set-cookie-params.php] For Session cookies use an int in seconds [360 = 6mins or 21600 = 6hours]

Also, for the session() cookie type make sure to add it before you start the session

$lifetime=600;
session_set_cookie_params($lifetime);
session_start();

People are also looking for solutions to the problem: php - load data local infile user provided VALUES

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.