Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 12:48:24 PM

Pages: [1]   Go Down
  Print  
Author Topic: How to block IP  (Read 1182 times)
planetlanham
Spaceship Navigator
*****
Offline Offline

Posts: 95


I never finish anyth


WWW
« on: November 24, 2009, 06:51:11 AM »

Hi all,

I'm a teacher & I have some students who are a little "too interested" in my family's website. I read an article (http://www.techiecorner.com/95/block-ip-from-accessing-website-using-htaccess/) that showed how to block an IP from viewing your site, but I don't think it works for what I need.

I have:
a primary domain - my family site
an add-on domain for my class page (is that the correct term? it's a separate .com but it's in a folder under my primary domain)

I want to block the school's IP from viewing my primary domain, but obviously not my class page.

I'm running Wordpress on both domains.

Anyone know how to do this?

thanks!
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #1 on: November 24, 2009, 07:15:30 AM »

I don't know about blocking one IP from your primary site but allowing it for an add-on site, using .htaccess. That might get complicated. I'm not familiar enough with the innards of WordPress to say exactly how to do it, but it might be possible to look at the IP address used for access, inside your family site, and reject it just for that site. WP might even have IP blocking built in. Mitch?

When you say that some students are "too interested" in your family site, are they getting in and reading/posting, or are they successfully hacking it? Don't you have user IDs and passwords to control access to your family site? I thought WP had such. If not, consider moving your family site down one level to a subdirectory, and password-protecting that directory, or maybe implementing IP blocking on that directory. Or, if your family site is being actually hacked, it sounds like you've got some security issues somewhere.
Logged

planetlanham
Spaceship Navigator
*****
Offline Offline

Posts: 95


I never finish anyth


WWW
« Reply #2 on: November 24, 2009, 07:22:50 AM »

Luckily it's not getting hacked.

I'm afraid the easiest thing to do is move my family site to a sub directory like you said. Luckily we have a holiday break starting tomorrow. Smile
Logged
Danielle
Guest
« Reply #3 on: November 24, 2009, 08:40:45 AM »

Actually, if you search online on how to do this, you get a great guide on wordpress itself:

http://codex.wordpress.org/Combating_Comment_Spam/Denying_Access

The issue with most of the methods listed is that your family site is the main domain and .htaccess entries blocking an IP will apply to all sub and addon domains inside public_html so you have to use a method that won't block the class page. The best one listed there for doing that would be the bottom one where they mention putting this code at the top of any page you don't want them to access:

<?php
$block = array("xxx.xxx.xxx.xxx", "yy.yy.y.yyy");

if (in_array ($_SERVER['REMOTE_ADDR'], $block)) {
    header("Location: http://google.com/");
    exit();
}
?>

Probably putting it into the index page for your family site would do the trick. You'd have to replace the "xxx.xxx.xxx.xxx" part with the actual IP you want to block.

If this is a family site and you do not want people other than your family viewing it, why allow access to anyone at all anyway? Why not just allow only family members to view it by password protecting it? Having it online without password protection means you have it getting searched by search engine spiders and linked in their indexes for other people to find. The only way to prevent access to people would be password protection in the long run.
Logged
planetlanham
Spaceship Navigator
*****
Offline Offline

Posts: 95


I never finish anyth


WWW
« Reply #4 on: November 24, 2009, 09:11:09 AM »

Cool - thanks for the page! I'll take a look at it later, but it really looks like just the thing.

I did password protecting, but many family members couldn't figure it out. (my dad couldn't, but my 80 year old grandmother could - go figure)

I'm not too worried about security, but I'd just like to make a select few "go away". I have some pictures of me working on a lab that I showed the class on the projector one day. Unfortunately, one of the students not destined for a science education (at least) noticed the URL was different. We were doing an internet assignment in class today and noticed a few of them gathered around a laptop with my daughter's picture on it.

It's the 1% that gives us 99% of the work...
Logged
planetlanham
Spaceship Navigator
*****
Offline Offline

Posts: 95


I never finish anyth


WWW
« Reply #5 on: November 24, 2009, 09:14:15 AM »

btw - I did a temporary thing for the day...

I blocked the wp-content folder of wordpress for just the school's IP. When accessing my family site you get unformatted text because it can't access the theme file. Class page works fine.

I like the idea of putting a header in my family page to block specific IPs. Hopefully I only need to do this on occassion. I should have it redirect to NSA.gov or someething.  Haha Anyone have a good scary but safe for school site to redirect to? Smile
Logged
planetlanham
Spaceship Navigator
*****
Offline Offline

Posts: 95


I never finish anyth


WWW
« Reply #6 on: November 24, 2009, 09:20:23 AM »

wow. that was much easier than it looked!

Thanks Tristan!!!

Now when I got to my site it redirects to nsa.gov

 Rofl  Roll  Clapping
Logged
Danielle
Guest
« Reply #7 on: November 24, 2009, 09:47:35 AM »

Great, glad it worked for you Smile
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #8 on: November 25, 2009, 07:17:38 AM »

Anyone have a good scary but safe for school site to redirect to? Smile

www.lawrencewelk.com
www.polkahalloffame.org
www.dietandexercise.com
www.putdownthatvideogame.org
www.educationisgoodforyou.com
...

Quote
Now when I got to my site it redirects to nsa.gov

Expect a knock on the door in the middle of the night...  Hypno
Logged

wektech
Master Jedi
*****
Offline Offline

Posts: 1031



WWW
« Reply #9 on: November 25, 2009, 07:28:26 AM »

Redirect them to here to the scariest site I know!
Logged

Pages: [1]   Go Up
  Print  
 
Jump to: