session active?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Vantuykom
Forum Newbie
Posts: 19
Joined: Fri Jul 04, 2003 6:22 am

session active?

Post by Vantuykom »

How can I find out if a certain SESSID is active?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Active as in user is still requesting pages?

Mac
Vantuykom
Forum Newbie
Posts: 19
Joined: Fri Jul 04, 2003 6:22 am

Post by Vantuykom »

yes, I want to know if the user is still requesting pages and did not close the browser without logging out...
I've found out that the sessions are staying on the server for a while, even without variables, so when I check if the session exists, I allways get 'yes'. thus I want to know if a session is active, not if it exists...
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I don't understand either how this session in php works. It starts off well but when destroying,unregistering,unsetting etc the $PHPSESSID still remains.
I still am not sure if its a bug or our mistake. But again how are others making it work ?
You may find some useful info here :
http://www.experts-exchange.com/Web/Web ... 35728.html
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Just found out that setcookie(session_name(),"",0,"/"); resets $PHPSESSID
Vantuykom
Forum Newbie
Posts: 19
Joined: Fri Jul 04, 2003 6:22 am

Post by Vantuykom »

that's interesting, but it isn't anything I can use, I really have to know if a session is active or not...
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

<?php
if (isset($PHPSESSID))
 print("Session active");
else
 print("Not Active !")
?>
I think because when session_start() does not takes place there is not variable called $PHPSESSID
Vantuykom
Forum Newbie
Posts: 19
Joined: Fri Jul 04, 2003 6:22 am

Post by Vantuykom »

but when somebody has another session open then it does not work
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

Vantuykom wrote:but when somebody has another session open then it does not work
Do the sessions eventually time out? 20 minutes or something? If not, is that a setting?

"Active" is sort of a misnomer in a web environment. I can connect to your site, then shut off my computer. No "I'm disconnecting" messages got passed back to you. So from the server's perspective, am I active or not? How would it know?

There is a setting called keep-alive, I think it's a header. But I don't know what it means exactly. If it involves the server pinging the client to make sure it's still there, or the client pinging the server to let it know it's still there, then you'd have to balance that resource cost against the resource cost of keeping sessions around you don't need until they time out.

Another question might be, do you NEED to use sessions? If it's a problem to keep them open, you could just handle your state-saving chores in another way. Hidden fields, query strings, that sort of thing.
Post Reply