473,569 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session OnEnd

Howdy,

For a challenge I took on a very large project and have decided to
develop it on Red Hat, using PHP and MySQL. I am pleased to say that
using Red Hat, PHP and MySQL has been extremely painless and a general
pleasure to use.

One thing has stumped me though.

Part of my site uses a forum/chat-area which highlights which users
are logged on and off of the site. Detecting when people logged off
would have been easy using ASP as I would use the Session_OnEnd
function within global.asa. But I am now horrified to discover that
PHP does not support this in anyway.

Surely this cannot be! If PHP lacks this fundamental ability I'm
afraid I am going to have to act like an immature schoolboy and slap
my forehead shouting 'Duh!!!' repeatedly.

I have read a few places that suggest using a timer to automatically
log people out of the database after ten minutes of inactivity. But I
simply refuse to believe there isn't a more elegant solution.

So any help or advice would be great.
Jul 17 '05 #1
4 5282
On 11 Nov 2003 12:19:22 -0800, br**********@st rikedesigns.co. uk (Brett Porter)
wrote:
For a challenge I took on a very large project and have decided to
develop it on Red Hat, using PHP and MySQL. I am pleased to say that
using Red Hat, PHP and MySQL has been extremely painless and a general
pleasure to use.

One thing has stumped me though.

Part of my site uses a forum/chat-area which highlights which users
are logged on and off of the site. Detecting when people logged off
would have been easy using ASP as I would use the Session_OnEnd
function within global.asa. But I am now horrified to discover that
PHP does not support this in anyway.
Probably not quite what you're after, but look at:

http://www.php.net/session-set-save-handler

Would be nice if you could hook into that (in your case in the destroy
handler), but still call the default session data handling.
Surely this cannot be! If PHP lacks this fundamental ability I'm
afraid I am going to have to act like an immature schoolboy and slap
my forehead shouting 'Duh!!!' repeatedly.

I have read a few places that suggest using a timer to automatically
log people out of the database after ten minutes of inactivity. But I
simply refuse to believe there isn't a more elegant solution.


Other than:

(a) explicit logoffs by the user
(b) timeouts

What other alternatives are there anyway? You can't detect when the user
closes their browser, after all. I see your point about having a callback when
the session is closed, but not about how it gets closed; ASP and PHP both have
a timeout after which the session is deleted (Session.Timeou t vs.
session.gc_maxl ifetime).

--
Andy Hassall (an**@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2
Brett Porter wrote:
Part of my site uses a forum/chat-area which highlights which users
are logged on and off of the site. Detecting when people logged off
would have been easy using ASP as I would use the Session_OnEnd
function within global.asa. But I am now horrified to discover that
PHP does not support this in anyway.

I have read a few places that suggest using a timer to automatically
log people out of the database after ten minutes of inactivity. But I
simply refuse to believe there isn't a more elegant solution.


This is how I handle it...

I use customized session handlers that store all the session information
into a database table:
CREATE TABLE psa_sessions (
sesskey varchar(32) NOT NULL default '',
user_name varchar(16) NOT NULL default '',
expiry int(11) NOT NULL default '0',
value text NOT NULL,
UNIQUE KEY sesskey (sesskey)
)

In the session read and write functions, I update the expiry of the
session record. te gc function (of course) deletes the record.

I then turn up the gc_probability (usually to 100% or until I notice a
difference). I have the session timeout set to what I *think* the
maximum time ($session_exp_i tem) someone would be on a single page
(depends on the type of site, etc.).

Then to see who's online, it's just a matter of checking the user_name
field in the session table. Since the timeouts are set reasonable, and
gc is running all the time, it's fairly accurate.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #3
br**********@st rikedesigns.co. uk (Brett Porter) wrote in message news:<a4******* *************** ****@posting.go ogle.com>...
Howdy,

For a challenge I took on a very large project and have decided to
develop it on Red Hat, using PHP and MySQL. I am pleased to say that
using Red Hat, PHP and MySQL has been extremely painless and a general
pleasure to use.

One thing has stumped me though.

Part of my site uses a forum/chat-area which highlights which users
are logged on and off of the site. Detecting when people logged off
would have been easy using ASP as I would use the Session_OnEnd
function within global.asa. But I am now horrified to discover that
PHP does not support this in anyway.


When user logins to the site, store his session_id in DB. (Look
at Martin's login script
http://martin.f2o.org/download/php-login-script/ ). And see if the
stored session for the user is active or not. For that you may use my
IsSessionActive () function found at
http://groups.google.com/groups?selm...ing.google.com

Also, look at this thread
http://groups.google.com/groups?thre...s.ci.uw.edu.pl

---
"Success = 10% sweat + 90% tears"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #4
Hi,

Thanks, for your suggestions, they certainly have given me food for
thought.

"Explicit logoffs by the user" I don't see as an option - you know
what users are like!

"session_set_sa ve_handler" looks like the solution I am after, I am
certainly warming to the idea of using my MySQL database to store
sessions rather than files as it ties in very well with my project
especially as the data stored within the session variables come from
the database!.

If I was to continue using files to save sessions is there any way I
can use the session_set_sav e_handler for the destroy function only so
that I don't have to rewrite the other functions?

I like the IsSessionActive () function, very clever, one concern I do
have though is that the site will be receiving a projected 2000+
visitors each day which I think *might* start to use valuable server
resources.

Again, many thanks,

Brett
Jul 17 '05 #5

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

Similar topics

3
1910
by: Pavils Jurjans | last post by:
Hello, I am looking for solution to assign the Session.onEnd event handler dynamically, at runtime, without using global.asax file. I am a bit sceptic wether that is possible, however I thought maybe it is possible to have a global.asax file with Session_onEnd method, that merely calls some delegate, and that delegate is assigned by my web...
4
1575
by: VB Programmer | last post by:
In my asp.net app I'm logging whenever someone signs in through the login page successfully. How do I log when they've "gone away", whether by closing the browser, the session vars for a person has expired, etc...? Thanks
5
2473
by: Raghu Raman | last post by:
HI, am using a simple project in asp.net using c#. if i put the break point in the application start & session start event , they are firing good .BUT WHEN i close my project while running on IE, the session end & application end event are not firing even though i put the break point there. Could u give me the solution for this how i...
0
3215
by: joseph conrad | last post by:
Hi, I tried to implement my own session handler in order to keep control on the process the drawback I foun it is not creating and storing in my cookie the PHPSESSID variable anymore. reading te documentation it seems it should do it anyway any advice?
14
2352
by: aroraamit81 | last post by:
Hi, I am facing a trouble. I have some Session variables in my code and somehow my session variables are getting mixed up with other users. For example User A has access to 10 companies and User B has access to 5, now when both of us hits to the server at the same time then their session variables gets mixedup means either User A and...
11
2084
by: David Thielen | last post by:
Hi; Is there some kind of session ID variable that I can get in the code behind and that is available in Session_OnEnd() to know what session ended? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com
1
2484
by: abcd | last post by:
I am using classic ASP. When the session times out theglobal.asa event called session_on end is invoked which is absolutely correct. When I explicitely do IIS reset or iis restart then again session_on end is invoked. How can I distguish in global.asa event session_on end that this is natural session time out or explicit IIS restart.... ...
5
2424
by: lyealain | last post by:
<% If Session("username") = "" Then Response.Redirect("/CLS/Login.asp") End If Dim conn Dim connectstr Dim db_name, db_username, db_userpassword Dim db_server Dim res
0
8138
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...
1
7681
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...
0
6290
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...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
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...
0
3662
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...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.