1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP code once per IP Address

Discussion in 'PHP & Perl' started by chickenugget, Feb 24, 2009.

Tags:
  1. chickenugget

    chickenugget Newbie

    Joined:
    Feb 24, 2009
    Messages:
    47
    Likes Received:
    10
    Occupation:
    Food
    Location:
    A deep fat fryer at McDonalds
    Hi All,

    I have a script that I only want to run once per IP address on my website. Is there some PHP code that I can use for this?

    Cheers
    Nugget
     
  2. Arthas

    Arthas BANNED BANNED

    Joined:
    Jan 5, 2009
    Messages:
    637
    Likes Received:
    322
    what language is the script you want to run written in?
     
  3. chickenugget

    chickenugget Newbie

    Joined:
    Feb 24, 2009
    Messages:
    47
    Likes Received:
    10
    Occupation:
    Food
    Location:
    A deep fat fryer at McDonalds
    Simple PHP code that calls an include file
     
  4. Arthas

    Arthas BANNED BANNED

    Joined:
    Jan 5, 2009
    Messages:
    637
    Likes Received:
    322
    here you go. i have included comments to help you.
    :detective

    PHP:
    <?php
    //note: you must make a table in your
    //database called ips with a field called ipaddress
    //
    //set your mysql options here
    $sqlserver "localhost";
    $sqluser "yourMySqlUsername";
    $sqlpassword "yourMysqlPass";
    $sqldatabase "YourMysqlDB-name";
    //end mysql settings

    mysql_connect($sqlserver$sqluser$sqlpassword);
    mysql_select_db($sqldatabase) or die(mysql_error() );

    $ip=$_SERVER['REMOTE_ADDR'];

    $ipsearch mysql_query("SELECT * FROM ips WHERE `ipaddress` = '$ip'");

    if(
    mysql_num_rows($ipsearch) < 1){

      
    //
      //Run your script here.
      //
      
      
    mysql_query("INSERT INTO ips (`ipaddress`) VALUES('$ip') ");
    }

    ?>
     
    • Thanks Thanks x 2
  5. chickenugget

    chickenugget Newbie

    Joined:
    Feb 24, 2009
    Messages:
    47
    Likes Received:
    10
    Occupation:
    Food
    Location:
    A deep fat fryer at McDonalds
    Mucho potato thanks. :tee: