October 23rd, 2000, 01:49 AM
I am looking to Count the number of users on the website, without having the user loggin. I have found code which does this but it is in ASP http://www.asp101.com/resources/active_users.asp , this uses Session and Application variables, it checks when a session starts and adds 1 to an Application variable, and when a session finishes it minus 1 from the same Application variable. I read that PHP doesn't have Application variables, only Session. Is it possible to add a Global variable in the php.ini to be used the same way? or is there a better way to do this. Please don't reply with a Database suggestion, as this problem doesn't require one, this is for a site with high traffic.
October 23rd, 2000, 02:37 AM
you could use sessions to controle users on your site, add one to a global session variable when a user enters, and minus one when they leave, you could set a cookie on the users computer or you could send a variable to every site to track the user.
when you are using sessions there is a "defined" SID variable which is set on session start and that variable is unique for every user.
hope this will lead you on your way
[This message has been edited by Ulrik N (edited October 23, 2000).]
October 23rd, 2000, 02:41 AM
Where do you setup the Global Variable? in the php.ini file?
How do you determine what the User has left the site, How do I capture the ending of a session with PHP??
October 23rd, 2000, 10:39 AM
$fp = fopen("counter.cnt","r+");
$counterval = fread($fp, 26 );
rewind( $fp );
$counterval = (integer)$counterval + 1;
fwrite( $fp, $counterval, 26);
fclose( $fp );
print "Total unique visitors are :".$counterval;
ps, don't forget to chmod 666 counter.cnt
October 23rd, 2000, 06:35 PM
Thank Lewi, just one more question, do I need to put this on all pages, or is there a file I can but it in the is continually read, like the php.ini file.
October 23rd, 2000, 06:56 PM
Now I need to be able to determine when the users session stops. Is there a flag or anything which is set went a session is closed by the user.
October 24th, 2000, 06:08 AM
u can put the code in a include file
so u only have to put that line in every file
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
as far as i know your are unable to directly see i a user logs of your site, it could be
done with java
or you could check for a period of time of user inactivity (this is the simples way)
October 24th, 2000, 07:40 PM
Well what I have ended up doing and currently testing is recording a time stamp and IP address in a file, so basically when the script is run it will check each line in File 'A' and write it file 'B' when checking if the datestamp is old (say 10-15 minutes) it will not copy it, and if the IP is the same as the current user it will update the time stamp, during this time I count the number of users and then copy file 'B' back over file 'A'.