...

View Full Version : need help with php script



miki754
11-18-2010, 01:51 AM
Hi all, I really need help on this script.
I am trying to add code if statement, so when people click/hit for 2nd time from the same ip address, the hit/click will not add 1.

Here is my IP location code

<?
$ip=$_SERVER['REMOTE_ADDR'];
echo "<b>IP Address= $ip</b>";

?>How to combine that code in the script below, could anyone help please ?




<?
$referrer_hit_count = 0;
if(isset($stats['referrer'])){
asort($stats['referrer']);
foreach($stats['referrer'] as $referrer => $hits){
$isreal = true;
if($referrer == '') {
$isreal = false;
$referrer = 'Direct / IM / Air Apps etc';
}
echo('<tr><td>');
if($isreal){
echo('<a href="'.$referrer.'" target="_blank">');
}
echo($referrer . '</td><td class="value">' . $hits . ' (' . number_format(100 * $hits / $link->hits, 1) . '%)</td></tr>');
if($isreal){
echo('</a>');
}
$referrer_hit_count += $hits;
}
}
$unknown_hits = $link->hits - $referrer_hit_count;
if($unknown_hits > 0){
echo('<tr><td>Unknown</td><td>' . $unknown_hits . ' (' . number_format(100 * $unknown_hits / $link->hits, 1) . '%)</td></tr>');
}
?>

codedragonxl
11-18-2010, 02:06 AM
I can't really tell, are you using anything to hold the data with?

miki754
11-18-2010, 02:36 AM
I can't really tell, are you using anything to hold the data with?


Here what I am trying to do.
If you go to storyku.com/ur if your click on the shorturl link or refresh the shorturl link, the hit will add 1. I want to make the hit/click not to add 1 for the second click from the same IP address.
Could you or anyone help?
Thank you

miki754
11-18-2010, 08:42 PM
I still have got any answer. Could anyone help, please?

codedragonxl
12-01-2010, 04:17 PM
You need something like SQL databases or flat-file, it's fairly easy to learn, and should seem like child's play, with the script you posted, there.

Lamped
12-01-2010, 04:44 PM
As codedragonxl says, a database would be handy here. Create a table like so:

ip int (unique, indexed)
count int

Code like:


// Connect to database
$handle = mysql_connect(...);
// Check if the ip already exists
$res = mysql_query('select * from `mycountertable` where `ip` = '.ip2long($_SERVER['REMOTE_ADDR']));
if (mysql_fetch_assoc($res)) {
// Yes, update
mysql_query('update `mycountertable` set `count` = `count`+1 where `ip` = '.ip2long($_SERVER['REMOTE_ADDR']);
} else {
// No, insert
mysql_query('insert into `mycountertable` (`ip`, `count`) values ('.ip2long($_SERVER['REMOTE_ADDR']).', 0)');
}

// Get counter
$res = mysql_query('select `count` from `mycountertable` where `ip` = '.ip2long($_SERVER['REMOTE_ADDR']));
// Should always succeed because we just added it above:
$row = mysql_fetch_assoc($res);
$counter = $row['count'];
echo('You\'ve been here '.$counter.' times!');

Very much untested.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum