Pages: [1]   Go Down
Send this topic | Print
Author Topic: [Resolved] Banning IP's  (Read 566 times)
Bullfrog110MB
Hyper-Active Member
***
Offline Offline

Posts: 287


I'm the shizzz.


WWW
« on: November 23, 2008, 12:18:16 PM »

Is there a way to ban an IP address from VIEWING a website. Like give them some error or something? Just don't want certain people to see my website.
« Last Edit: November 24, 2008, 02:11:04 AM by bullfrog » Logged

Join the forums! --->  www.bullfrog.110mb.com
Myles Grey
Full-Time Programmer
Super Authority member
******
Offline Offline

Posts: 1863


Programmer's Delight Release - 90%


WWW
« Reply #1 on: November 23, 2008, 01:06:01 PM »

Is this for your blog? I'm not sure if your blog script comes with something automatically with this. You could try putting this at the top of the page (Make a backup of the files first):

Code:
<?php
// IPs to ban
$ips[] = "127.0.0.1";
$ips[] = "127.0.0.2";
$ips[] = "127.0.0.3";

// Get IP
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
// Check if they're banned
if (in_array($ip,$ips))
  exit(
header("HTTP/1.1 403 Forbidden"));
?>

Logged

IE has the best Quirks
Almost every site you see runs on Quirks, not standards




Remember to mark your topic as [resolved]
Bullfrog110MB
Hyper-Active Member
***
Offline Offline

Posts: 287


I'm the shizzz.


WWW
« Reply #2 on: November 23, 2008, 01:55:38 PM »

I copied the code directly into the index.php file... Errors.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /www/110mb.com/b/u/l/l/f/r/o/g/bullfrog/htdocs/index.php:3) in /www/110mb.com/b/u/l/l/f/r/o/g/bullfrog/htdocs/fp-includes/core/core.session.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /www/110mb.com/b/u/l/l/f/r/o/g/bullfrog/htdocs/index.php:3) in /www/110mb.com/b/u/l/l/f/r/o/g/bullfrog/htdocs/fp-includes/core/core.theme.php on line 155


Can anybody do it for me? Or is there even a way to.
Logged

Join the forums! --->  www.bullfrog.110mb.com
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Offline Offline

Posts: 15644


experimental theologian


WWW
« Reply #3 on: November 23, 2008, 01:56:24 PM »

Yeah... you want to make sure there's no whitespace before that <?php or after the ?>
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
Bullfrog110MB
Hyper-Active Member
***
Offline Offline

Posts: 287


I'm the shizzz.


WWW
« Reply #4 on: November 23, 2008, 02:10:17 PM »

Source code to my index.php file, can you rewrite it for me?

<html dir="ltr">
    <head>
        <?php

   // Example of use
   require_once 'defaults.php';
   include(INDEX);

?>
        <title></title>
    </head>
    <body spellcheck="false">
    </body>
</html>
Logged

Join the forums! --->  www.bullfrog.110mb.com
Myles Grey
Full-Time Programmer
Super Authority member
******
Offline Offline

Posts: 1863


Programmer's Delight Release - 90%


WWW
« Reply #5 on: November 23, 2008, 03:33:27 PM »

Try this:

Code:
<?php
// IPs to ban
$ips[] = "127.0.0.1";
$ips[] = "127.0.0.2";
$ips[] = "127.0.0.3";

// Get IP
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

// Check if they're banned
if (in_array($ip,$ips))
  exit(
header("HTTP/1.1 403 Forbidden"));


   
// Example of use
   
require_once 'defaults.php';
   include(
INDEX);

?>

<html dir="ltr">
    <head>
        <title></title>
    </head>
    <body spellcheck="false">
    </body>
</html>
Logged

IE has the best Quirks
Almost every site you see runs on Quirks, not standards




Remember to mark your topic as [resolved]
tpog
Super Authority member
******
Online Online

Posts: 1544


WWW
« Reply #6 on: November 23, 2008, 06:17:31 PM »

There's some discussion about this here http://www.110mb.com/forum/how-to-ban-ip-address-t19552.0.html

The trouble is, if they know they're banned, there's ways around it, so rather than "banning" them, maybe you should take them to their own version of the site.
Logged
Bullfrog110MB
Hyper-Active Member
***
Offline Offline

Posts: 287


I'm the shizzz.


WWW
« Reply #7 on: November 24, 2008, 01:47:15 AM »

The code works, but I tried banning myself to see the forbidden page, I got this error.

Warning: Cannot modify header information - headers already sent by (output started at /www/110mb.com/b/u/l/l/f/r/o/g/bullfrog/htdocs/index.php:3) in /www/110mb.com/b/u/l/l/f/r/o/g/bullfrog/htdocs/index.php on line 14
Logged

Join the forums! --->  www.bullfrog.110mb.com
tpog
Super Authority member
******
Online Online

Posts: 1544


WWW
« Reply #8 on: November 24, 2008, 01:52:35 AM »

Certain functionality needs to be included before the <html> tag - otherwise you see this error.

How are you updating this file? Looking at your earlier source - it looks like it may have been maintained by the 110mb file manager.

Be aware that this re-formats the source, inserting an <html> tag before any code, which may be causing your problem.

You may need to update this locally (e.g. via notepad) and update via ftp to get around this.
Logged
Bullfrog110MB
Hyper-Active Member
***
Offline Offline

Posts: 287


I'm the shizzz.


WWW
« Reply #9 on: November 24, 2008, 02:10:36 AM »

Yeah, it works now!

Thank you!
Logged

Join the forums! --->  www.bullfrog.110mb.com
Pages: [1]   Go Up
Send this topic | Print
Jump to: