Results 1 to 7 of 7

Thread: Submitting a form according to IP

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Submitting a form according to IP

    Is there a way to have a form check the mysql DB IP field if the IP matches that of the person filling out te form it displays message or grays out the submitt button

  2. #2
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This hasn't been tested but should work:

    Code:
    <?
    // Database Login Function
    function db_connect()
    {
        $result = mysql_pconnect("localhost", "USERNAME", "PASSWORD");
        if (!$result)
            return false;
        if (!mysql_select_db("DATABASE_NAME"))
            return false;
    
        return $result;
    }
    
    // Get Computers IP address
    $ip_address = $_SERVER['REMOTE_ADDR'];
    
    // Search From IP Address Database
    $sql="SELECT * FROM banned_ips WHERE ip_address = '".$ip_address."'";
    $query = mysql_query($sql, db_connect()) or die(mysql_error());
    $result=mysql_fetch_array($query);
    $num_rows = mysql_num_rows($query); 
    
    // IP Address was not found
    if ($result["ip_address"] == ""){
    
    //IP address found display the submit button.
    
    echo '<input type="submit" name="button" id="button" value="Submit">';
    
    } else {
    
    // IP address is banned display message
    echo 'Sorry you are not allowed to use this form!';
    
    }
    
    ?>

  3. #3
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    couldnt get it to work

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    The idea is something like this

    Code:
    $ip_address = $_SERVER['REMOTE_ADDR'];
    The above code will give you the client IP address. You can do whatever you want with it. I mean at the time of store it in your db and later check it with incoming requests. But what I feel is it may not provide you with the needed situation always.

  5. #5
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I was trying to figure out a way to prevent the same person from being able to submit more than once. It’s not real critical, but a deterrence. Only a few will be post to the form and their not real savvy about there IP so for what I’m trying to accomplish it would be good.

    I tried the above code several differant ways and it displayed
    echo '<input type="submit" name="button" id="button" value="Submit">';} else {// IP address is banned display messageecho 'Sorry you are not allowed to use this form!';}
    At the top of the form page with everything I tries.
    My submit button is <input type='submit' value='Submit Form'> which is going here <form enctype='multipart/form-data' action='form.php' method='post' name="Enter_Form"
    Last edited by big-dog1965; 01-03-2008 at 03:35 AM.

  6. #6
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    post you whole page php code for me to review

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    okay well upon entering the site you should check their IP.

    as code_exploiter said
    $ip_address = $_SERVER['REMOTE_ADDR'];
    will give you the IP Address of the browser.
    From there, you can processes it as necessary. For your concerns you want two checks. First you want to see if its on some "banned ip" list, and some "already posted" list. Both sets should be stored somewhere on the server, either in a text field or a database table. It would probably be easiest for the "Already Posted" to be in the posts table, however the banned IP has no defined place that they are. If you put in a text field you can check the IP, however if you have a database table you can see other meta information alot easier, like date/time banned, who banned, why was person banned? This can all be done in a text file too, but some people find it easier to do in a table ...

    So you just need to create a query that will take the IP Address of the user as explained above and run it again both of those lists... if it's a hit then you display some error message, if not it means that the user can make a post.

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
  •