We help IT Professionals succeed at work.
Get Started

Page ip block script

dk4210
dk4210 asked
on
368 Views
Last Modified: 2013-12-12
Hello,
Can you guys tell me what I am doing wrong here?


I downloaded the following script and tried to modify it, but It doesn't work. I am trying to figure out why I can't get it right..

On this line  -- > $bmode = 2; . The initial options were 0 or 1. I modified the following
---------------------------------------------------------------------------------------------------

$blockmsg = "<br/><br/><br/><p><center>You have been Blocked for guestbook abuse.<br/> <br/><br/><a href=\"http://www.whatever.com\">Click here for more information</a></center></p>";

It was an array. I didn't like that because for every ip that I enter in it has it's own message. I want just one default message to be displayed for all the blocked ip's


-----------------------------------------------------------------------------------------------------

 if ($bmode == 2) {
    if ($REMOTE_ADDR == $blockip[$y] || ($brange == $blockip[$y])) {
      echo '$blockmsg';    
    } else {
      $allow="Yes";
    }
  }


What my thoughts were here was that I used the same one that the developer used for 1 but added just an echo statement to echo $blockmsg.  It won't work correctly though.. Please help.. I was hoping that I could do this myself, but I guess not..



-----------------------------------------------------------------------------------------------------

Full Script..


<?
// Copyright (c) 2003-2004 Robert Murdock (robert@darpac.com)
// ALL RIGHTS RESERVED

// Mode.  If you set this to 1 then you will BLOCK IPS in the blockip array.
// If set to 0, then you will be ALLOW ONLY IP's in the blockip array.
// Addenum by Dan Kelly. If set to 2 then only primary message will show.

$bmode = 2;

// Note: if you are blocking a range (2.2.x) Make sure you put the
//       trailing . (period/dot) at the end or it may cause issues
//       with good ip ranges.
//

// $block ip is the IP of the person that you wish to block.
// You can add as many IP's as needed but keep the same format.
// The last IP will not need a ',' after it. The others will.
//
// Example:
//
// $blockip = array("1.1.1.1",
//                  "2.2.2.2",
//                  "3.3."
//                 );

$blockip = array("1.1.1.1",
                 "2.2.2.2.",
             "3.3.3.3",
                  "209.164.239.146",
                 );



// $blockmsg is the message the user will see if they are blocked.
//
// Example:
//
// $blockmsg = array("1.1.1.1 Blocked for guestbook abuse.",
//                   "209.164.239.146 Blocked for guestbook abuse.",
//                   "3.3.3.3 We are temporarily down.",
//                  );


$blockmsg = "<br/><br/><br/><p><center>You have been Blocked for guestbook abuse.<br/> <br/><br/><a href=\"http://www.fbi.gov\">Click here for more information</a></center></p>";


                 

// Nothing to change below this line ------------------

$x = count($blockip);


for ($y = 0; $y < $x; $y++) {
 
  $brange = substr($REMOTE_ADDR, 0, strlen($blockip[$y]));

  if ($bmode == 1) {
    if ($REMOTE_ADDR == $blockip[$y] || ($brange == $blockip[$y])) {
      exit($blockmsg[$y]);    
    } else {
      $allow="Yes";
    }
  }
 
  if ($bmode == 0) {
    if ($REMOTE_ADDR == $blockip[$y] || ($brange == $blockip[$y])) {
      // return(1);
      $allow="Yes";  
    }
  }

}
 if ($bmode == 2) {
    if ($REMOTE_ADDR == $blockip[$y] || ($brange == $blockip[$y])) {
      echo '$blockmsg';    
    } else {
      $allow="Yes";
    }
  }

      

if ($allow != "Yes") exit($blockmsg);

?>
Comment
Watch Question
Top Expert 2005
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE