Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile need help with php script

    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 ?


    PHP Code:
        <?
            $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->hits1) . '%)</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->hits1) . '%)</td></tr>');
            }
            
    ?>
    Last edited by Brandoe85; 11-19-2010 at 11:22 AM.

  • #2
    New to the CF scene
    Join Date
    Nov 2010
    Location
    Earth.
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't really tell, are you using anything to hold the data with?

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by codedragonxl View Post
    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

  • #4
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I still have got any answer. Could anyone help, please?

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Location
    Earth.
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    As codedragonxl says, a database would be handy here. Create a table like so:

    ip int (unique, indexed)
    count int

    Code like:
    PHP Code:
    // 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.
    Last edited by Lamped; 12-01-2010 at 04:47 PM. Reason: Added get counter and fixed some syntax.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •