[SOLVED]Sessions Help

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

User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Sessions time out after a specified time (set to 15 mins by default? correct me if I'm wrong). Try if a session timeout = session destroy. If so: tutto bene, you're sorted.
If not, and you're running mySQL, I'd set up a 30 min cron job to clean up the table.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Well, session destroy is already automatically called by php when the thing times out. But yea, either the cron job or the query I just posted seem like the only ways. I figure if there was an easy way to do it, phpBB would have the answer in their code, but they don't either.

Is it possible for me to scan through every session file on the server and pull out the user names of the people logged in?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Why don't you go with session destroy and simply add your SQL statement in the custom session handler.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Either you don't understand what I'm saying or I don't understand what you're saying. Cause that does not solve my problem.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Sorry, my mistake. I was, for some reason, thinking that session_destroy() would be automatically called on session timeout.

You have to use the garbage collection to clean up your session table.

In the custom session-functions (see php manual) you have a function called garbage collection. That will get called when the session times out. Write your SQL query that deletes the data from the session table there.

Zend has a tutorial on this: http://www.zend.com/zend/tut/session.php

Does that help with your problem?
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Yes, now that is exactly what I wanted to know. I'll try to implement my own session handler with a garbage collection function and will let you know if it works. Thanks!

The other tutorial on Zend is probably better at explaining this.
http://www.zend.com/zend/spotlight/code ... -wade8.php
Post Reply