What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Blocking an IP

Pages: (2): « First [ 1 ] 2 » Last »
Blocking an IP
Author: Message:
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. Dodgy  Blocking an IP
Does anyone know of a good IP blocker in php that will block IP's from your site?
[Image: top.gif]
04-09-2004 09:45 PM
Profile PM Web Find Quote Report
Digirat
New Member
*


Posts: 13
Joined: Apr 2004
RE: Blocking an IP
why don't you use htaccess? i'm assuming you're already running apache due to the php you're asking for
04-09-2004 09:58 PM
Profile E-Mail PM Web Find Quote Report
sock
Elite Member
*****

Avatar
Back in White! (with red stripes)

Posts: 1112
Reputation: 31
39 / Male / Flag
Joined: Nov 2002
Status: Away
RE: Blocking an IP
IIS has (crappy) PHP support too... :p


Anyway, this code should work (although .htaccess is a good alternative):


<?php
  $ip = getenv("REMOTE_ADDR");
  $proxy = getenv("HTTP_X_FORWARDED_FOR");
  if ($proxy) {  // HTTP proxy used
    $pos = 0;
    while (($pos < strlen($proxy)) && ($proxy{$pos} != ','))
      $pos++;
    $ip = substr($proxy,0,$pos);
  }
  if ($ip == "1.2.3.4")
    die("Sorry, you are not cool enough to view this page.");
?>



Just change the IP address in red to the one you wish to block. :p If you want to block more than one IP address, you can use || (or) in the IF condition. If you want to block lots of them, you should probably use a better method of matching... Like using an array or something. :-/ Or just use .htaccess. :refuck:

Anyway, you can place the code at the top of the page, or perhaps under the <BODY> tag.

This post was edited on 04-10-2004 at 02:43 PM by sock.
[Image: patchoulolhaxun7.jpg]
04-10-2004 02:27 PM
Profile E-Mail PM Find Quote Report
Wabz
Elite Member
*****

Avatar
Its Groovy Baby!

Posts: 3459
Reputation: 29
39 / Male / Flag
Joined: Jan 2003
RE: Blocking an IP
This might help
Mess.be Forum Moderator
Messenger Plus ex-IRC Network Admin
Gimme a Rep!
04-10-2004 04:18 PM
Profile E-Mail PM Web Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. RE: Blocking an IP
Where can I edit the htaccess? Or do I have to make one?
[Image: top.gif]
04-10-2004 04:34 PM
Profile PM Web Find Quote Report
Anubis
Elite Member
*****

Avatar
42

Posts: 2695
Reputation: 64
34 / Male / Flag
Joined: Oct 2003
RE: Blocking an IP
Couldn't a JavaScript code do the same if PHP is unsupported?
[Image: anubis5hq.png]
04-10-2004 04:37 PM
Profile PM Find Quote Report
reisyboy
Elite Member
*****

Avatar
Messenger Oldie ;-)

Posts: 2107
Reputation: 10
36 / Male / –
Joined: May 2002
RE: Blocking an IP
How can you block IP on ur PC? Is it in the HOSTS?
Reisyboy: He is the priest to guide us from evil.. which isn’t working… so we call him Frier Tuck
04-10-2004 04:40 PM
Profile E-Mail PM Web Find Quote Report
sock
Elite Member
*****

Avatar
Back in White! (with red stripes)

Posts: 1112
Reputation: 31
39 / Male / Flag
Joined: Nov 2002
Status: Away
RE: Blocking an IP
quote:
Originally posted by DJeX
Where can I edit the htaccess? Or do I have to make one?
You need to make one... You can make several ones and put them in different directories. But I don't know much about .htaccess so I can't help you with that really. :p


quote:
Originally posted by anubis_kree_
Couldn't a JavaScript code do the same if PHP is unsupported?
Theoretically, it could do something of the sort, but it would be quite stupid to do it that way. :p You'd have to print the IP address in the code somewhere, which again requires PHP (or other server-side script)... And the banned user could still read the source or simply disable JavaScript. It's stupid. :p


quote:
Originally posted by reisyboy
How can you block IP on ur PC? Is it in the HOSTS?
No, that simply acts as DNS cache which overrides DNS lookups on your computer. It can be abused to block access to certain domain names from your PC (by pointing them to localhost or something), but not actual IP addresses. You'd have to use a firewall to do that. :-/

This post was edited on 04-10-2004 at 05:36 PM by sock.
[Image: patchoulolhaxun7.jpg]
04-10-2004 05:28 PM
Profile E-Mail PM Find Quote Report
Anubis
Elite Member
*****

Avatar
42

Posts: 2695
Reputation: 64
34 / Male / Flag
Joined: Oct 2003
RE: Blocking an IP
quote:
Originally posted by sock
Theoretically, it could do something of the sort, but it would be quite stupid to do it that way. You'd have to print the IP address in the code somewhere, which again requires PHP (or other server-side script)... And the banned user could still read the source or simply disable JavaScript. It's stupid.
Not if they guy's a n00b, but I see your point...
[Image: anubis5hq.png]
04-10-2004 05:36 PM
Profile PM Find Quote Report
stonesour
Full Member
***

Avatar
Posts: 901231

Posts: 205
36 / Male / –
Joined: Nov 2003
RE: Blocking an IP
I use this

code:
<?php


function ip_check()
{
    // Addresses to block.
    $block_ip[] = '203.217.64.174';
    // Check current IP.
    if (in_array($_SERVER['REMOTE_ADDR'], $block_ip))
    {
        return false;
    }
    else
    {
        return true;
    }
}
?>


Then in your index file or whatever put this include
code:
<?php    include 'bannedip.php';    if (!ip_check())   
{     
header( "Location: http://ng.audiodragon.net/bannage.php");
}
?>


Change the header location bit to the redirect site, bannedip.php to the name of your script.

You can also just display text using the echo command..
04-10-2004 06:43 PM
Profile E-Mail PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On