IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Visitors Online

, With PHP (no MySQL is needed)


FaLgoR
no avatar
Super Member
*********
Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



Post #1 post Feb 16 2005, 11:20 PM
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.

CODE

<?
$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 wink.gif
Go to the top of the page
+Quote Post
no9t9
no avatar
Privileged Member
*********
Group: Members
Posts: 773
Joined: 4-November 04
Member No.: 2,118



Post #2 post Feb 17 2005, 04:38 AM
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.
Go to the top of the page
+Quote Post
FaLgoR
no avatar
Super Member
*********
Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



Post #3 post Feb 17 2005, 04:51 PM
Thank you =]
I don't know why I'm tryn to get reputation points, but I like to collect them, just for fun =P
Go to the top of the page
+Quote Post
nancmu
no avatar
Advanced Member
*******
Group: Members
Posts: 136
Joined: 20-October 04
From: Thailand
Member No.: 1,840



Post #4 post Feb 20 2005, 06:26 AM
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"];
}

smile.gif laugh.gif
Go to the top of the page
+Quote Post
no9t9
no avatar
Privileged Member
*********
Group: Members
Posts: 773
Joined: 4-November 04
Member No.: 2,118



Post #5 post Feb 20 2005, 03:04 PM
what about detecting if they are on something like AOL proxy?
Go to the top of the page
+Quote Post
nancmu
no avatar
Advanced Member
*******
Group: Members
Posts: 136
Joined: 20-October 04
From: Thailand
Member No.: 1,840



Post #6 post Feb 21 2005, 05:43 AM
QUOTE
what about detecting if they are on something like AOL proxy?

detecting huh.gif 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 unsure.gif . But if you use my code the number are 2 online users wink.gif .
Go to the top of the page
+Quote Post
NotoriousZach
no avatar
Member [Level 1]
****
Group: Members
Posts: 55
Joined: 26-February 05
Member No.: 3,996



Post #7 post Mar 5 2005, 12:08 AM
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.......
Go to the top of the page
+Quote Post
alexia
no avatar
Super Member
*********
Group: Members
Posts: 310
Joined: 9-February 05
From: Italian
Member No.: 3,677



Post #8 post Mar 5 2005, 02:19 PM
@time= show time
$REMOTE_ADDR = show visitor IP
$string = have $REMOTE_ADDR and @time
$a = fopen("online.txt", "a+"); = open flat file
fputs($a, $string); = write $a and $string string at file
fclose($a); = close file
nice script
really nice
i write this post for help to learn php
but i know very low about php blink.gif
Go to the top of the page
+Quote Post
HmmZ
no avatar
Super Member
*********
Group: Members
Posts: 362
Joined: 2-March 05
From: The Netherlands
Member No.: 4,097



Post #9 post Mar 5 2005, 10:32 PM
no9t9

Could you share the code for "most users ever online" here? smile.gif

and yea, simplicity is the key here, love the script!
Go to the top of the page
+Quote Post
mobious
no avatar
Advanced Member
*******
Group: Members
Posts: 113
Joined: 14-January 05
From: Philippines
Member No.: 3,271



Post #10 post Mar 6 2005, 02:01 AM
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.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No new 44 OpaQue 172,104 30th November 2008 - 07:52 PM
Last post by: iG-iAdmin ...not
No new   20 max_powers1987 2,420 9th August 2004 - 12:16 AM
Last post by: LILJOHN
No New Posts   0 bowjthewen 531 5th August 2004 - 06:48 AM
Last post by: bowjthewen
No New Posts   2 psp-playstation 417 19th December 2008 - 03:29 AM
Last post by: Ruben
No new   15 Dehornos 1,611 2nd January 2009 - 09:04 AM
Last post by: contactskn
No new   51 Torch89 4,958 6th January 2009 - 07:06 AM
Last post by: DarkNova
No New Posts 5 chinfo 704 7th December 2008 - 04:58 PM
Last post by: Variablez
No new   15 psp-playstation 1,020 3rd September 2004 - 12:42 AM
Last post by: annylei
No new   26 Raptrex 20,072 20th May 2006 - 04:59 AM
Last post by: Ojikitsune
No New Posts   9 X3r0X 825 31st August 2004 - 06:09 AM
Last post by: wassie
No new   15 dundun2007 2,112 22nd October 2008 - 04:09 AM
Last post by: iGuest-Whark
No New Posts   2 DataHead 528 5th September 2004 - 10:00 PM
Last post by: Portuga
No new   55 darkplagued 8,837 13th January 2005 - 03:45 AM
Last post by: NuHoaXuLa
No New Posts   0 synderoxide 363 4th September 2004 - 02:02 PM
Last post by: synderoxide
No New Posts   3 UberGrossMann 628 10th June 2008 - 05:15 AM
Last post by: FeedBacker