473,382 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

detecting session timeout or tracking concurrent sessions

Can anyone tell me if there is a way in PHP to determine when a session
times out on the server or how many concurrent sessions there are in
your application?

Oct 22 '06 #1
2 11157
runner7 wrote:
Can anyone tell me if there is a way in PHP to determine when a session
times out on the server or how many concurrent sessions there are in
your application?
Hi runner,

This is how PHP implements sessions:
If you use session out of the box, they use filestorage.
Every time a request to php is made that uses a session, PHP tries to
retrieve the accompanying file based on the sessionid.
If that file is too old, the session is considered gone and you'll have to
start a new one.
From your scripts point of view there is no session at all when this
happens.

In this sheme you cannot 'do something' when a session expires.
Also you cannot easily find out how many session are active, but it can be
done:
- Count the number of not stale PHP sessionfiles in the directory where PHP
stores them.

To gain more grip on sessions, you can use databasestorage of sessions.
You'll have to write your own sessionlogic, and change your the php.ini, or
use session_set(), as follows:
session.save_handler = "user"

and you'll also have to write some routines.

Read more here:
http://nl2.php.net/manual/en/ref.session.php

and for your own sessionhandler:
http://nl2.php.net/manual/en/functio...ve-handler.php

It also contains links to examples. Read the usercontributed notes too.

Good luck.

Regards,
Erwin Moller
Oct 23 '06 #2
Rik
runner7 wrote:
Can anyone tell me if there is a way in PHP to determine when a
session times out on the server or how many concurrent sessions there
are in your application?
Not directly.
As indicated by Erwin you could create your own session-handler, but I
usually opt for another option:
- use the normal session-handler to create sessions.
- store all date (including time of last action, etc.) in a database.

Now on a pageview, a custom session include does the following (note I only
use sessions on sites that require a login, so you'll get that flow too
:-).

- session_start();
- check in the database which session-ids are timed out according to your
own logic, and:
- delete them from the database.
- possibly log them
- possibly perform other actions
- check wether this user is blocked (either by user-id or IP (be carefull
with IP-blocking! IP's are mostly dynamic nowadays, and if you block one
IP, you could end up blocking a user you don't wish to block).
- check the session-id the determine wether the user is one of the already
logged in users.
- now you can check how many people are logged in atm in your database.
- if the user isn't logged in, and only a certain number of users may be
logged in, determine wether this use is allowed to login.
- if the user is allowed, possibly check for a previous set cookie (when
the user has perhaps indicated to keep him logged in).
- if not, check login parameters from a form, and check those against
username & password.
Essentially, this script will only time-out sessions when the/a page is
requested. On a site with medium traffic, or when your logging out logic
doesn't really require a precise time, this will be OK.
--
Rik Wasmus
Oct 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: riprod | last post by:
Someone in the IIS newsgroup suggest I post this here, so sorry in advance for the cross posting. I have a Win 2003 SP1 with IIS 6 and host about 40 websites, most of them useing ASP/VB with...
5
by: Jon Booth | last post by:
I want to write an apsx page that when loaded does not refresh Session.Timeout. It is going to be running in an iframe and refreshing every couple of minutes. example. User has 15 minutes left...
11
by: Vishal | last post by:
Hello, can anybody tell me how I can extend the session expiry time? Is it done via code or via IIS? Sorry I am new and dont know about this.
8
by: bdeviled | last post by:
I am deploying to a web environment that uses load balancing and to insure that sessions persist across servers, the environment uses SQL to manage sessions. The machine.config file determines how...
17
by: jensen bredal | last post by:
Hello, i'm struggling with a somehow badly understood session scenario. I provide acces to my pages based on form authentication using Session cookies. Som of my pages are supposed to be...
5
by: Ed | last post by:
I have some questions in regards to Session variables and IIS Recycling: 1. Does the IIS setting 'Shutdown worker process after being idle' affect an application's session variables? Or is IIS...
25
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
I tried: <sessionState timeout="1"> </sessionState> bounced IIS, and after 1 minute still had a session. ??? -- thanks - dave
3
by: Sems | last post by:
Hi I'm using the Session_End event in the global.asax to detect if a users sessions has ended. Is there any way to tell if the session end is due to it being expired and not abandoned? I'm...
5
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
Hi All, I am using asp.net session state service to store session. The concurrent online user will be almost 2000. Could asp.net session state service afford this? Is there any limitation...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.