Jump to content

Automatic IP blocking from DB


anybody99

Recommended Posts

hey, i look for a code [maybe some 1 knows already] to automaticley block an IP address that it is located in the DB, to prevent users from accessing my site twice.

if some1 know already when i can get that code that i will be glad, also i have found that code:

$ip = $_SERVER['REMOTE_ADDR'];

if($ip == "123.123.123.123" || $ip == "213.213.213.213") {
  // YOUR BANNED
} else {
  // YOUR NOT BANNED
}

 

but it is not automatic and not from DB.

 

-Rob

Link to comment
Share on other sites

A simple example.

 

<?php

  // connect to db.
  $sql = "SELECT ip FROM banned WHERE ip = '{$_SERVER['REMOTE_ADDR']}'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      // user is banned.
    } else {
      // user is ok.
    }
  }

?>

Link to comment
Share on other sites

Write an insert query that does so.

 

A big part of learning to program is to learn how to take examples and turn them into usable code. Im not going to write the thing for you, you'll need to think for yourself. Sorry.

Link to comment
Share on other sites

well i dont want or need to learn the language because i am not using it.

 

Well then I recommend you look in the freelance section and pay someone to design for you. This is all about helping coders learn and develop their website, not a charity for those that don't want to bother.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.