PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old September 6th, 2002, 11:09 PM
alsaffar alsaffar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 58 alsaffar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Counter Problem

I found a nice counter script at hotscripts.com but the problem is all the counter scripts that I found are either incrementing on every reload page or locking the ip so your ip will never be counted again, never!!!

I need a counter script, since my host provides me a free counter that increments every page load! (what a host ha?)

the script that I need is to store "lets say" the last 10 ip's and then re-write on the oldest one, I get tired of looking and searching but I couldn't find any.

Can anyone modify the script that I found to store just n ips and re-write the oldest?

<?

////////////////////////////////////////////////////////////
//
// counter.php - a graphical counter
//
////////////////////////////////////////////////////////////
//
// This script outputs a "hit count" displayed using digit
// images and formatted according to the setting for
// "minDigits". The hit count can be incremented on every
// page hit or only for unique IP addresses (the
// "countOnce" feature).
//
// See readme.txt for more information.
//
// Author: Jon Thomas <http://jp.thomas.name>
// Last Modified: 6/11/02
//
// You may freely use, modify, and distribute this script.
//
////////////////////////////////////////////////////////////

// define the variables
$file = "count.txt"; // text file that stores hit count
$imgExtension = "gif"; // file extension of digit images
$minDigits = 0; // the minimum # of digits to display
// set to 0 to display only needed digits
$countOnce = 0; // set to 1 to count unique IPs only
// set to 0 to count all hits
$ipFile = "ips.txt"; // text file that stores IP addresses

// DO NOT EDIT BELOW THIS POINT UNLESS YOU KNOW PHP! //

// get the current hit count
$fp_count = fopen($file, "r");
$count = fread($fp_count, filesize($file));
fclose($fp_count);

// if the "countOnce" feature is enabled
if ($countOnce) {
// open the IP address file
$fp_ips = fopen($ipFile, "r");

// compare each entry with the user's IP address
while (!feof($fp_ips)) {
// get an entry from the IP file
$ip = fgets($fp_ips, 20);

// if the user's IP matches, set the user to old
if ($ip == $REMOTE_ADDR . "rn") {
$is_old = 1;
break;
}

// otherwise, set the user to new
else {
$is_old = 0;
}
}

// close the IP address file
fclose($fp_ips);

// if the user is not old, add his IP to the IP file
if (!$is_old) {
// reopen the IP address file
$fp_ips = fopen($ipFile, "a");

// add the user's IP address
fputs($fp_ips, $REMOTE_ADDR . "rn");

// close the IP address file
fclose($fp_ips);
}
}

// if the "countOnce" feature is disabled, set the user to new
else {
$is_old = 0;
}

// if the user is not old, increment the counter
if (!$is_old) {
$count++;

// save the new hit count
$fp_count = fopen($file, "w");
fputs($fp_count, $count);
fclose($fp_count);
}

// count the number of digits in the hit count
$digits = strlen($count);

// if minDigits is set and the number of digits is less than minDigits, add leading zeroes
if ($minDigits && $digits < $minDigits) {
// find the difference between minDigits and the number of digits in the count
$diff = $minDigits - $digits;

// add a number of leading zeroes equal to the difference
for ($i = 0; $i < $diff; $i++) {
$count = "0" . $count;
}

// set digits equal to minDigits
$digits = $minDigits;
}

// print the appropriate image for each digit in the hit count
for ($i = 0; $i < $digits; $i++)
{
// get a digit from the hit count
$digit = substr("$count", $i, 1);

// print the image for that digit
echo "<img src=images/digits/$digit.$imgExtension>";
}

?>

or any other script using MySQL to achieve my goal?

Reply With Quote
  #2  
Old September 7th, 2002, 12:20 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Counter Problem

I whipped up a little function for you real quick. Let me know if it is useful:

http://codewalkers.com/seecode/163.html

Reply With Quote
  #3  
Old September 7th, 2002, 01:05 AM
siteworkspro.com siteworkspro.com is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 92 siteworkspro.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to siteworkspro.com Send a message via AIM to siteworkspro.com
RE: Counter Problem

have you tried setting a cookie for say a day? and check the existance of a cookie before incrementing the counter??

Reply With Quote
  #4  
Old September 7th, 2002, 09:27 AM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
RE: Counter Problem

Matt's script uses an expire function so each IP address will expire after 10 minutes.

Do you still want a script to record the last 10 IPs, or is that OK?

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Counter Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway