sessiontimeout in php

Hello experts.
I need help to set a sessiontimeout to the following code .On sessiontimeout set userid to 0.
<?php
session_start();
$_SESSION['userid']=$_GET['userid'];
$URL= $_GET['location'];
header("Location: $URL");
?>
LVL 2
PanosAsked:
Who is Participating?
 
Ray PaseurCommented:
Yes, you can change this value.  It may be necessary to make changes in more than one place.  See these links.
http://php.net/manual/en/function.session-set-cookie-params.php
http://php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime

See also the variables here:
session.gc_probability
session.gc_divisor
session.gc_maxlifetime

Whenever session_start() is called, the garbage collector will go into action looking for expired session data.  As old data is found, the GC will delete it.  What this means in practice is that some old session data may be left on the server after the (default) 24 minute lifetime.  But it also means that any new client interaction wil trigger the cleanup first, before creating the new client session.
http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime
0
 
jrm213jrm213Commented:
Hi,

I am not sure what you are trying to do. When the session times out, $_SESSION['userid'] will no longer exist. If you are passing it through the URL then every time you run the above code it will either extend the current session or create a new one.

Could you post a little more information about what you are trying to accomplish?

Thanks!
0
 
PanosAuthor Commented:
Hi jrm213jrm213.
I'm using cf serverlanguage and i needed to set the same userid in cf and php.
There is a question history :
1.http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Cold_Fusion_Markup_Language/Q_27498569.html
2.http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27501125.html
 The details in the questions are no more needed. Finally i found a way to set the same session.userid in cf server and php.(i want to use cometchat plugin that is using php language).
I need also to set the same session timeout in both languages. If users cf session is over - the user will be offline in the php plugin too.
Here is the code that the plugin is using for setting the userid
function getUserID() {
      $userid = 0;
      
      if (!empty($_SESSION['userid'])) {
            $userid = $_SESSION['userid'];
      }

      return $userid;
}

>.....it through the URL then every time you run the above code it will either extend the current session or create a new one.
i'm passing the value only after a success login once.

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Ray PaseurCommented:
Let me try to explain a little bit about how sessions work in PHP.  When you start a session with the session_start() function, the PHP session handler sets a cookie on the browser (that will be returned on every subsequent page request) and it stores its information in a temporary "save" variable.  On every subsequent page request the client browser will return the cookie. The cookie will expire at the end of the browser life, meaning when the last instance of the browser is closed, the cookie is lost.  This ends the session.  Irrespective of the cookie, the PHP garbage collection routines will delete the data from the temporary storage after about 24 minutes of client inactivity.  Either event, cookie deletion or data deletion, closes the session and leaves the client "logged out."
0
 
PanosAuthor Commented:
Hi Ray_Paseur
Cf is working similar to this.
The question is if i can change/set a custom value for 24m.(i can do this in cf).

(By the way i found a solution for my previous question.The problem was not with php but on every call using the cfhttp tag i got a new session in php. using a cflocation like the header - location function in php did solve the problem.)
0
 
PanosAuthor Commented:
Thank you very much for your help.
regards
panos
0
 
Ray PaseurCommented:
Thanks for the points - it's a great question, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.