Results 1 to 2 of 2

Thread: How to: Prevent Duplicate Accounts by IP address?

  1. #1
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to: Prevent Duplicate Accounts by IP address?

    How do I create a code in PHP and MySQL to prevent people from creating duplicate accounts by recording their IPs in the database?

    So far I've found this piece of PHP code but not sure what to do for the database:

    PHP Code:
    <?php

    // * Check for duplicates.

    $request "SELECT * FROM jamroom_check_dup_ip";
    $db_result mysql_query($request);
    $ipaddress mysql_fetch_object($db_result);

    $num_rows mysql_num_rows($db_result);
    $row_count 0;
     
    while (
    $row_count $num_rows) { // While I haven't checked all the rows.
       
    $ipaddress mysql_fetch_object($db_result);  // Put each object into $ipaddress.
       
    $row_count++;   // * And add one to row count.
           
    if ($ipaddress->session == $session) { // If session equates to session...
                   
    if ($ipaddress->username == $username) {
                       if (
    $ipaddress->password == $password) {
                           if (
    $ipaddress->day == $day) {
                               if (
    $ipaddress->securityquestion == $securityquestion) {
                                   if (
    $ipaddress->securityanswer == $securityanswer) {
               
    displayError("Duplicate accounts are not allowed.");
               exit();
           }
                   }
                       }
                           }
    }
    ?>
    Any help is greatly appreciated.

    Thanks in advance.

  2. #2
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Smile

    if "jamroom_check_dup_ip" is the table where ip addresses are stored
    you may go like this

    <?php
    $ipnow = $_SERVER['REMOTE_ADDR'];

    $sql="select ipfieldname from jamroom_check_dup_ip where ipfieldname='$ipnow'";

    $rs = mysql_query($sql);
    $num = mysql_num_rows($rs);
    if($num<1){
    // add the records
    } else {
    print 'Duplicate IP or record from same Ip already exists in the database';
    }
    ?>

Bookmarks

Posting Permissions

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