|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 217 Joined: 2-January 05 Member No.: 3,084 |
Post
#1
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 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 773 Joined: 4-November 04 Member No.: 2,118 |
Post
#2
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. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 217 Joined: 2-January 05 Member No.: 3,084 |
Post
#3
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 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 136 Joined: 20-October 04 From: Thailand Member No.: 1,840 |
Post
#4
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"]; } |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 773 Joined: 4-November 04 Member No.: 2,118 |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 136 Joined: 20-October 04 From: Thailand Member No.: 1,840 |
Post
#6
Feb 21 2005, 05:43 AM
QUOTE what about detecting if they are on something like AOL proxy? detecting 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 |
![]() ![]() ![]() ![]() Group: Members
Posts: 55 Joined: 26-February 05 Member No.: 3,996 |
Post
#7
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....... |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 310 Joined: 9-February 05 From: Italian Member No.: 3,677 |
Post
#8
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 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 362 Joined: 2-March 05 From: The Netherlands Member No.: 4,097 |
Post
#9
Mar 5 2005, 10:32 PM
no9t9 Could you share the code for "most users ever online" here? and yea, simplicity is the key here, love the script! |
![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 113 Joined: 14-January 05 From: Philippines Member No.: 3,271 |
Post
#10
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.
|
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
44 | OpaQue | 172,104 | 30th November 2008 - 07:52 PM Last post by: iG-iAdmin ...not |
|||
![]() |
20 | max_powers1987 | 2,420 | 9th August 2004 - 12:16 AM Last post by: LILJOHN |
|||
![]() |
0 | bowjthewen | 531 | 5th August 2004 - 06:48 AM Last post by: bowjthewen |
|||
![]() |
2 | psp-playstation | 417 | 19th December 2008 - 03:29 AM Last post by: Ruben |
|||
![]() |
15 | Dehornos | 1,611 | 2nd January 2009 - 09:04 AM Last post by: contactskn |
|||
![]() |
51 | Torch89 | 4,958 | 6th January 2009 - 07:06 AM Last post by: DarkNova |
|||
![]() |
5 | chinfo | 704 | 7th December 2008 - 04:58 PM Last post by: Variablez |
|||
![]() |
15 | psp-playstation | 1,020 | 3rd September 2004 - 12:42 AM Last post by: annylei |
|||
![]() |
26 | Raptrex | 20,072 | 20th May 2006 - 04:59 AM Last post by: Ojikitsune |
|||
![]() |
9 | X3r0X | 825 | 31st August 2004 - 06:09 AM Last post by: wassie |
|||
![]() |
15 | dundun2007 | 2,112 | 22nd October 2008 - 04:09 AM Last post by: iGuest-Whark |
|||
![]() |
2 | DataHead | 528 | 5th September 2004 - 10:00 PM Last post by: Portuga |
|||
![]() |
55 | darkplagued | 8,837 | 13th January 2005 - 03:45 AM Last post by: NuHoaXuLa |
|||
![]() |
0 | synderoxide | 363 | 4th September 2004 - 02:02 PM Last post by: synderoxide |
|||
![]() |
3 | UberGrossMann | 628 | 10th June 2008 - 05:15 AM Last post by: FeedBacker |
|||