Hi
I am creating session for my website,i want to expire the session after particular time for the user logged in,i want to retrieve current time in PHP,i used a time() function in php to get current time,but i got sequence of number.can oyu help me how to get current time and steps to expire the session for the logged user.i want to expire the session after one hour the user logs in.Help me out for this problem


Regards,
Vidhya.

use to access server time

<? echo date('h:s:i'); ?>

You can session register the time when a user logs in on a different script(or even a function) that won't be used again. Using normal variables will change the time if a page is refreshed.
Try that

$_SESSION['login_time']=time();

To expire the session after a given time please check out the use of cookies at http://www.php.net. (search for setcookie in the function list)

[code=pet peeve]
sql time or php date are 10 decimal digits representing the number of seconds from 1/1/1970 (doh,, 1970 or 1980? )
human readable representations of date() or time() are unneccessary and waste processor time
the computer uses digits better than text representations
thus time() + 300 = five minutes from now
thus date() + 3600 = one hour from now
storing timestamps in database, cookies or sessions is much more efficient, than strtotime()-ing a text string to work with it, then formatting the time back as a text string.,

[code=pet peeve]
sql time or php date are 10 decimal digits representing the number of seconds from 1/1/1970 (doh,, 1970 or 1980? )
human readable representations of date() or time() are unneccessary and waste processor time
the computer uses digits better than text representations
thus time() + 300 = five minutes from now
thus date() + 3600 = one hour from now
storing timestamps in database, cookies or sessions is much more efficient, than strtotime()-ing a text string to work with it, then formatting the time back as a text string.,

it's 1970, it's known as the epoch if you want to look it up

Hi,
I can't end the session after particular time say 30 mins,i want the exact coding to end the session for particular user

Regards,
Vidhya

get user id and apply check if the user id is equal to your required user id
destroy the session

<? 
if($userid==1)
{
session_destroy();
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.