Adrian
Adrian

Reputation: 2291

Block user ip registration using mysql, php and html

I would like to know how is it possible to block a list of given ips from a mysql database table of ips. For example i have a registration form and if the user has a different ip than the one from the mysql dbs he should see the form else he should see a message on that page "You are not allowed to use VPN/Proxy ips on this website". First how do i create the mysql table and column, what properties do i need to add, so i can import the ips from a csv file.

MYSQL

CREATE TABLE IF NOT EXISTS 'blocked_ips'....... 

and don't know how exactly to continue. Tried adding a column in phpmyadmin with VARCHAR(15) and after tried importing the csv file of ips, but it doesn't work, it only imports 2 rows and has only 00 containing in the 2 rows

<?php
//check for user ip
$ip = $_SERVER['REMOTE_ADDR'];
compare the ip got from the user with the mysql table column with ips
if the $ip matches with one from the table echo a message on the same page, (no pop-up).
 else {
 will echo the form below
 ?>

 <DOCTYPE html!>
 <head>
  <title> Registration</title>
   meta
   meta
 </head>
 <body>
  <table class="colortext" width="100%"  border="0" cellspacing="0" cellpadding="0">
   <tr>
    <td width="30%">&nbsp;</td>
    <td height="20" width="70%">{advertiser_msg:8921}</td>
   </tr>
   <tr>
    <td>{advertiser_msg:1092} <span class="mandatory">*</span></td>
    <td>{USERFIELD}<span id="fg" style="display: none;white-space: nowrap;"></td>
   </tr>
  </form>
 </body>
 </html>

I am a noob in this please help.

Upvotes: 0

Views: 453

Answers (1)

Vaibs_Cool
Vaibs_Cool

Reputation: 6160

mysql_select_db("your database name")   or die(mysql_error()); 
 # Full Text Attempt
        $query = mysql_query("SELECT `IP` FROM `your table` WHERE `IP` = '$ip'");
        or
        $query = mysql_query("SELECT `IP` FROM `database` WHERE `IP` LIKE '%$ip%'");
        //chk for banned ip ipaddress

        if (mysql_num_rows($query) > 0)
        {
            echo "<p> You are not allowed to register with proxy VPN </p>";
        }

    ?>

Upvotes: 1

Related Questions