Welcome Guest, Not a member yet? Register   Sign In
setting session time out
#1

[eluser]Volkscom[/eluser]
Hi,

I'm using php session functions in my project and not using codeiniter's session class.I need to set session time out.How can I do this?.
I write the following function in helper and this give an error

in myhelp_helper.php{

function sesion_timeout(){
// set timeout period in seconds
$inactive = 60;
// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['start'];
if($session_life > $inactive)
{ session_destroy(); }
}
$_SESSION['timeout'] = time();
}
}

I anyone know to solve this,Please help me.......
Thanks in advance
#2

[eluser]jrtashjian[/eluser]
There is no need to write your own functions for the sessions as CodeIgniter has provided a class for it. There is no difference between CodeIgniter sessions and PHP sessions (in case of confusion)...

I say, use CodeIgniters Session library. You can set session timeouts in the config file.
#3

[eluser]danmontgomery[/eluser]
[quote author="jrtashjian" date="1288818993"]There is no need to write your own functions for the sessions as CodeIgniter has provided a class for it. There is no difference between CodeIgniter sessions and PHP sessions (in case of confusion)...

I say, use CodeIgniters Session library. You can set session timeouts in the config file.[/quote]

Yes there is, codeigniter sessions use cookies by default, or the database if you have that option enabled. There is a native session library, though.
#4

[eluser]jrtashjian[/eluser]
@noctrum: I assumed it was using php sessions, however you are correct in saying it uses cookies.
@Volkscom: I would create my session, somewhat like what I have below.

Starting the session:
Code:
function session_create()
{
    session_start();
    
    // timeout in 60 seconds
    $timeout = 60;
    
    $_SESSION['timeout'] = time() + $timeout;
}

Checking if the session has timed-out
Code:
function session_timed_out()
{
    if( time() > $_SESSION['timeout'] )
    {
        session_destroy();
        return TRUE;
    }
    return FALSE;
}

Use it like so:
Code:
session_create();

if( session_timed_out() )
{
    // do something if the session is no longer valid (timed-out)
}
else
{
    // continue the script because the user session is still valid
}
#5

[eluser]Volkscom[/eluser]
hi,
Thanks for your reply!....
I tried your function and wrote it as a helper.I need to set session time out, when the user is idle for a long time.Now the function is not checking whether the the user is idle for a long time or not. If know how to solve, please help me..




Theme © iAndrew 2016 - Forum software by © MyBB