Page 1 of 1

Sessions and Viewers

Posted: Thu Jul 03, 2008 8:18 am
by Frozenlight777
I'm trying to write a little functions that would display the number of concurrent sessions. This site does it with the number of "Guests" but I'm not sure where to begin.

Logically this is how I'm thinking of coding it (pseudo code)

Code: Select all

function foo(){
  $IP = $_SERVER['REMOTE_ADDR'];
  $_SESSION['IP'] = $IP;
  $result = count($_SESSION['IP']);
  return $result;
}
foo();
I thought of using the IP just because of it's unique characteristic, there's got to be a better way to do it.
I know that will only work for each session which would return just 1. Is there a tutorial or something out there someone can share? Thanks guys.

Re: Sessions and Viewers

Posted: Thu Jul 03, 2008 4:00 pm
by jaoudestudios
you have the right idea

only I would not use ip as in theory there should only be 1 ip per user, in actual fact it is not true due to sub networks (local networks, wireless etc).

I would use the php function uniqid(rand(), true).

This will give you a real unique number as it is based on micro unix timestamp.

Also if you want to use count($var) then it needs to be an array....so use $var[] = unique_no as this will keep incrementing the array $var, then you can use count.

This will keep incrementing forever, so you really need to put a time feature on. So that if a user goes visiting around the site their unique id also has a timestamp associated with it which will keep getting updated every time they visit a page. So your count would only count the people who have been active within the last 10mins or so.

Hope that makes sense.