getting the number of sessions

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
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

getting the number of sessions

Post by psychotomus »

is there away to get the number of sessions currently in use like $_SESSION['test'], to get how many users on the site have a #_SESSION['test'] variable in use?
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

i guess this isnt possible?
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

I think usually when you create a session you log it in a file or database some where with a timestamp. I dont use sessions though.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Are you using the default "file" based session or a custon DB handler?
In either case it should be possible to find the information you want. In the former case you can count the number of files in the tmp folder. If you want to know what variables are set you'll have to parse the files there.

If you're using a custom DB handler it should be trivial to gather either piece of information, but the exact method will depend on your handler.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

im using session_start(); then later i do

$_SESSION['whatever'] = "test";

where are these files stored at?
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

Wouldn;t counting the files /tmp give you ALL the sessions if your using shared hosting, not just your sites?

Keith
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

im trying to get the number of users logged into my site, i figure the easyest way to do it is by getting the number of $_SESSIONS' i have open since if they dont have a specific session set they cant log in or browse other pages on the site.
Post Reply