Destroy session php after some time

I am currently saving a session in my form page:

$testingvalue = "SESSION TEST";

$_SESSION['testing'] = $testingvalue;

On another page I am calling the session to use the value:


Now I want to use the

session_destroy[];

to destroy the session. But what I would like to do is destroy the session after 2 hours have been passed.

Any idea on how to do it and also where should I put it?

I have something like this:

 

Will that work?

If I am inactive for more than 2 hours this should be blank?:

echo $_SESSION['testing'];

Destroy Session after 5 minutes in PHP

By default the expiry time of any particular session that is created is 1440 secs i.e [24*60]. ie 24 minutes around .

But in some cases there is necessity to change this default time .

There are two ways of doing this :

1] Either we can make changes in the php.ini file, and change the configuration .

But in this case the default time for all the sites working on that server will change.

2] There is another method to getrid of this. we can logically change the destroy time of session. here at the time of creation of session we calculate the system current time  and as the user browse to different pages of the script will check for the expiry time i.e is explicitly declared as session-expiry[time previously noted at the time of session creation + the time for which you want your session to be maintained].

The session get destroyed at that particular time and redirect the user to the homepage of that script.

index.php

 

Chủ Đề