473,804 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11181
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_ha ndler = "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
18778
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 access databases. The server is a Dell Dual 2.4Ghz XEON with 512Mb Ram. Every few days I get the error 'HTTP/1.1 New Session Failed' and the server stops showing the sites. It comes right after a bit and then the error comes back. I
5
2676
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 until session expires. iframe.aspx loads and session still has 15 minutes left. Is this possible? I was trying to grab session.timeout at the begininning of the page (init)
11
3014
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
5500
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 all applications will use sessions and to insure that all application use this method, the session properties cannot be overriden. Within the sessionstate tags, the webadmin (upon my request)r emoved the property for timeout, hoping that...
17
5219
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 running continuously and refreshing once an hour. I there set timeout= 61 in <sessionState section and on my page it says <meta http-equiv="refresh" content="3600">. I also set timeout=120 in the <forms section of web.config to make sure
5
3188
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 checking that all sessions are done before shutting down the worker processes? 2. Does the Recycle worker processes setting kill all session variables of
25
6105
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
7601
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 trying to show the user a popup if their session has expired due to a timeout. Whats the best way to do this?
5
5901
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 about asp.net session state service? -Billy
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.