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

[???] Allowing only one visit per IP address ...

Discussion in 'PHP & Perl' started by OTrap, Jun 30, 2014.

  1. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,286
    Likes Received:
    1,052
    I'm presuming to do this with an if/else statement, predominantly because I'm still something of a PHP novice.

    What I'm wanting to do is this:

    Visitor A comes to my site. His IP address is 111.111.111.111. He fills in an opt-in form. He then attempts to go to the initial page again and submit ANOTHER set of details in the form.

    I'd like to be able to show a different page of code if the IP has been tracked before. Something like this:

    PHP:
    <?php 

    get visitor
    's IP address;

    check his IP address against a database;


    if his IP shows up on the database {

    echo "You'
    ve been here before.";

    } else {

    echo "
    Heyyou are new!";

    }

    write the visitor's IP address to the database;

    ?>
    Am I biting off more than I should be by wanting to do this? If it's too complicated, I wouldn't want anyone to put too much time into explaining it, but if it's a quick or simple process, I'd sure love some help.
     
  2. easy2earn

    easy2earn Regular Member

    Joined:
    Jun 5, 2013
    Messages:
    293
    Likes Received:
    57
    Occupation:
    IT
    • Thanks Thanks x 1
  3. easy2earn

    easy2earn Regular Member

    Joined:
    Jun 5, 2013
    Messages:
    293
    Likes Received:
    57
    Occupation:
    IT
    • Thanks Thanks x 1
    Last edited: Jul 1, 2014
  4. OldFatGuy

    OldFatGuy Regular Member

    Joined:
    Jun 4, 2009
    Messages:
    253
    Likes Received:
    149
    Unless there's some particular reason it's important to track the IP, just use a cookie instead.
     
    • Thanks Thanks x 2
  5. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,286
    Likes Received:
    1,052
    Man, thank you guys for your help.

    OldFatGuy, there is indeed a reason for tracking the IP. ;)
     
  6. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    I might not be answering your question.

    But just a note here, as mentioned by OldFatGuy, you should use a cookie at least.
    Of course you can combine with a ip check as well.
    The reason is because different machines may have the same ip (e.g. they go through same subnet, proxy etc) and in other case, those dynamic connection (adsl or mobile), the ip from same machine may change.
     
    • Thanks Thanks x 1
  7. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,286
    Likes Received:
    1,052
    The distinction in IP address is actually more important than the distinction in user. However, I will use cookies as well, as it certainly will only make things more genuine.

    Much appreciated guys! I've got it worked out!

    This place is awesome.
     
  8. member8200

    member8200 Regular Member

    Joined:
    Aug 9, 2014
    Messages:
    469
    Likes Received:
    33
  9. sssteve

    sssteve Registered Member

    Joined:
    Oct 24, 2014
    Messages:
    57
    Likes Received:
    15
    Home Page:
    This is some PHP I used on one of my old sites.

    I was using a MySql Database, and recorded the IP when a person registered.

    Everytime someone registered it would check the database to see if that IP had been used before.

    Its a basic way of doing it, but it works, the bold text are my notes, it was written this way to suit other stuff going on in the script, but it can be used and changed to suit you if you use php and mysql.

    $userip=$_SERVER['REMOTE_ADDR']; it would pickup the users ip
    $sql9 = "select * from `users` where `IP` = '$userip'"; it would check the database for that ip
    $result9 = mysql_query($sql9); the result would store in $result9
    $total9 = mysql_num_rows($result9); $total9 would equal how many times the ip address had been found
    $rs9 = mysql_fetch_row($result9);


    if ($total9 > 0) {
    $check=9;
    }

    if ($total > 0) {
    $check=1;
    }