mushfiq
mushfiq

Reputation: 1600

php scripts logout too quickly

I was working in a project where another developer wrote the code,while a user is login the session_start() as usual and then he is cheking like belows:

    if($a['userName'] == $username && $a['password'] == $pwd)   
{
                $_SESSION['id'] = $a['id'];         ?>       <script language="javascript"type="text/javascript">window.location="host.php";</script> }     else    {       
$msg= "Invalid Username Password";  
}

And when a user want to use the form after couple of seconds its logout and user can not submit data.

I have tried increasing session life time duration:

$sessionCookieExpireTime=8*60*60;
session_set_cookie_params($sessionCookieExpireTime); 

And also tried with increasing session lifetime in runtime like below:

ini_set('session.gc_maxlifetime', '3600');

And finally tried by increasing php.ini session lifetime . Unfortunately those did not work.

One thing I should mention that,there is no session_destroy() for logout issues.

Thanks in advance.

Upvotes: 2

Views: 2032

Answers (2)

Matijs
Matijs

Reputation: 2553

What kind of server are you working on?

On a shared server that runs multiple sites that use a shared session directory the session.gc_maxlifetime is in effect the shortest lifetime of all sites accessing that shared directory.

If the problem is on a development server, find out where the session files are stored and look at what happens to them.

It is also possible that the directory where the sessions are stored is not writeable. In that case the session variable is never stored in the first place.

In all three cases: try to store the session files in a different directory. In code you have to set the session directory with session_save_path() before you call session_start().

Upvotes: 2

AjayR
AjayR

Reputation: 4179

The timeout occurs when user idle activity for certain time. There is no way to logout automatically unless using session_destroy.

It may be possible that your code $a['id'];

returns null by chance. Also, you need to checkout which page is getting logged out. Giving the full code may be easy to identify the issue.

Upvotes: 0

Related Questions