sessiontimeout in php

Hello experts.
I need help to set a sessiontimeout to the following code .On sessiontimeout set userid to 0.
$URL= $_GET['location'];
header("Location: $URL");
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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?

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 :
 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;

> 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.

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."
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

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.)
Ray PaseurCommented:
Yes, you can change this value.  It may be necessary to make changes in more than one place.  See these links.

See also the variables here:

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PanosAuthor Commented:
Thank you very much for your help.
Ray PaseurCommented:
Thanks for the points - it's a great question, ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.