473,323 Members | 1,551 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,323 software developers and data experts.

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 5272
On 11 Nov 2003 12:19:22 -0800, br**********@strikedesigns.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.Timeout vs.
session.gc_maxlifetime).

--
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_item) 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**********@strikedesigns.co.uk (Brett Porter) wrote in message news:<a4**************************@posting.google. 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_save_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_save_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
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...
4
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...
5
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...
0
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...
14
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...
11
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...
1
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...
5
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.