Jump to content

Unique visits


subhomoy

Recommended Posts

Hello every one i've created this code which will track the unique visits per 24 hr with the help of date and ip....

The code is shown below...

<?php
require_once '../dbconfig.php';
echo $date = date("Y-m-d");
$uid = $_SESSION['id'];
$ip = $_SERVER['HTTP_HOST'];
$adi = $_REQUEST['aid'];
$a = mysql_query("SELECT * FROM ad_clk WHERE id='$adi'") or die(mysql_error());
while($te = mysql_fetch_array($a)){
    $imp = $te['impression'];
   echo $money = $te['money'];
    $link = $te['link'];
}
?>
<form method="post" action="">
    <input type="submit" name="submit" value="Credit" />
</form>
<?php
if(isset($_REQUEST['submit'])){
    $r = @mysql_query("SELECT * FROM ad_clk_hits WHERE adv_id='$adi'") or die(mysql_error());
    while($re = mysql_fetch_array($r)){
        $date1 = $re['date'];
        $ip1 = $re['ip'];
        $adv = $re['adv_id'];
        
    }
    if(($ip==$ip1) && ($date==$date1) && ($adi==$adv)){
        echo 'You have already visited this advertisement today';
    }
    else{
        echo "Thank You";
       $imp = $imp-1;
        $e = mysql_query("UPDATE ad_clk SET impression='$imp' WHERE id='$adi'") or die(mysql_error());
        $w = mysql_query("INSERT IGNORE INTO ad_clk_hits(id,user_id,adv_id,date,ip) VALUES('','$uid','$adi','$date','$ip')") or die(mysql_error());
    }
        
}
clearstatcache();
?>
<iframe src="<?php echo $link; ?>" width="100%" height="100%"></iframe>



Its working fine but there is one problem...

 

I have tested with changing the date of my computer and its counting unique but sometimes when i'm refreshing the page continuosly by pressing F5 for testing purpose, some times the duplicate values with same date and ip are dumped into database... and again after some more refreshes  it works fine...

 

Why the script is behaving abnormally????

 

Any help will be greatly appreciated...

 

Thank u in advance...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.