Ask a Question related to PHP Development, Design and Development.
-
Brett Porter #1
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.
Brett Porter Guest
-
#16263 [Com]: session.start() create new empty session file and not resume existing session
ID: 16263 Comment by: pat at burnttech dot com Reported By: kur at natur dot cuni dot cz Status: No Feedback... -
Problem with global.asa database and Session OnEnd
Agggghhhh.... I've read countless posting and still can't get an answer that works. I'm trying to update a record when a session ends. Here's the... -
Webmethod OnEnd
Hello, I have a requirement on my webservice. I want to track when a request had come to my webmethod and when the response was completed. I... -
How can I "know" the difference between a session timed out and a session that did session.abort?
Any clues? Thanks for your time. Adam -
#25307 [NEW]: Crash when session.serialize_handler=wddx & session, post, get vars
From: cristea at pntcd dot ro Operating system: any PHP version: 4CVS-2003-08-29 (stable) PHP Bug Type: Session related Bug... -
Justin Koivisto #2
Re: Session OnEnd
Brett Porter wrote:
This is how I handle it...> 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.
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 - [email]spam@koivi.com[/email]
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Justin Koivisto Guest
-
Andy Hassall #3
Re: Session OnEnd
On 11 Nov 2003 12:19:22 -0800, [email]brett.porter@strikedesigns.co.uk[/email] (Brett Porter)
wrote:
Probably not quite what you're after, but look at:>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.
[url]http://www.php.net/session-set-save-handler[/url]
Would be nice if you could hook into that (in your case in the destroy
handler), but still call the default session data handling.
Other than:>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.
(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 (andy@andyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
Space: disk usage analysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
Andy Hassall Guest
-
R. Rajesh Jeba Anbiah #4
Re: Session OnEnd
[email]brett.porter@strikedesigns.co.uk[/email] (Brett Porter) wrote in message news:<a4930814.0311111219.3d83ffbb@posting.google. com>...
When user logins to the site, store his session_id in DB. (Look> 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.
at Martin's login script
[url]http://martin.f2o.org/download/php-login-script/[/url] ). And see if the
stored session for the user is active or not. For that you may use my
IsSessionActive() function found at
[url]http://groups.google.com/groups?selm=abc4d8b8.0310130436.5096fa2b%40posting .google.com[/url]
Also, look at this thread
[url]http://groups.google.com/groups?threadm=3FAFE1F0.E8E8F165%40venus.ci.uw.edu .pl[/url]
---
"Success = 10% sweat + 90% tears"
Email: rrjanbiah-at-Y!com
R. Rajesh Jeba Anbiah Guest
-
Brett Porter #5
Re: Session OnEnd
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
Brett Porter Guest



Reply With Quote

