Jump to content
xisto Community
Sign in to follow this  
FaLgoR

Visitors Online With PHP (no MySQL is needed)

Recommended Posts

Another script, which shows the visitors onlineat the moment in your site. This script was not made by me, I just think it will be very usefull to u.

<?$timeout = 15; // change it. It is the timer which will delete the member of  online list (in minutes)if (!$datei) $datei = dirname(__FILE__)."/online.txt";$time = @time();$ip = $REMOTE_ADDR;$string = "$ip|$time\n";$a = fopen("online.txt", "a+");fputs($a, $string);fclose($a);$timeout = time()-(60*$timeout);$all = "";$i = 0;$datei = file("online.txt");for ($num = 0; $num < count($datei); $num++) {	$pieces = explode("|",$datei[$num]);  if ($pieces[1] > $timeout) {  	$all .= $pieces[0];  	$all .= ",";  }	$i++;}$all = substr($all,0,strlen($all)-1);$arraypieces = explode(",",$all);$useronline = count(array_flip(array_flip($arraypieces)));echo $useronline;$dell = "";for ($numm = 0; $numm < count($datei); $numm++) {	$tiles = explode("|",$datei[$numm]);  if ($tiles[1] > $timeout) {  	$dell .= "$tiles[0]|$tiles[1]";  }}if (!$datei) $datei = dirname(__FILE__)."/online.txt";$time = @time();$ip = $REMOTE_ADDR;$string = "$dell";$a = fopen("online.txt", "w+");fputs($a, $string);fclose($a);?>

Now, just make an blank file called online.txt. That's all! I hope I've helped you :D

Share this post


Link to post
Share on other sites

great script. works like a charm. The only thing I did to it was add a "Most users ever online" O, and I guess I'll give you rep for it.. you seem to have been very helpful with php for many other users.

Share this post


Link to post
Share on other sites

I think i used to see the script at hotscripts.com but that's so good when you brought it here.Anyways on the code "$ip = $REMOTE_ADDR;" wasn't included for share internet but if you want to check for share ip...Try this...if ($_SERVER['HTTP_CLIENT_IP']) { $ip $_SERVER['HTTP_CLIENT_IP'];} elseif (ereg("[0-9]",$_SERVER["HTTP_X_FORWARDED_FOR"] )) { $ip $_SERVER["HTTP_X_FORWARDED_FOR"];} else { $ip $_SERVER["REMOTE_ADDR"];} :P;)

Share this post


Link to post
Share on other sites

what about detecting if they are on something like AOL proxy?

detecting :P did you mean that code?OK, guy. i will tell you..

if you use "$ip = $REMOTE_ADDR;" code then go to internet cafe and open your website from 2 computers in there, your web will show only 1 number of user online ;) . But if you use my code the number are 2 online users :D .

Share this post


Link to post
Share on other sites

Hey thanks that works great, remember you may want to chmod the online.txt page to read and write I believe that is 666 if my memory serves me right. Also another helpful tip. Instead of putting all that in your page use the include funtion.<? Include("filename.php") ?> Just put that in your main site and save the large piece of coding into filename.php.......

Share this post


Link to post
Share on other sites

@time= show time$REMOTE_ADDR = show visitor IP$string = have $REMOTE_ADDR and @time$a = fopen("online.txt", "a+"); = open flat filefputs($a, $string); = write $a and $string string at filefclose($a); = close filenice scriptreally nice i write this post for help to learn php but i know very low about php :D

Share this post


Link to post
Share on other sites

i just wanna remind everyone that using this script (which uses a flat file) is not recommended if your site has a high overhead. as it will have undesirable effects. your script may not open a file pointer since it is already opened by another. and will render the script useless. if your site has a high overhead, i suggest to migrate to sql.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.