• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

IP restriction and blocking...?

1. I have an .htaccess file. Do I edit it and upload it via the FTP? How do I go about adding a code to only allow my IP address to view site?

2. What steps do I need to take to upload,make it work etc; once I have added the code?

3. How do I make a backup/copy of the .htaccess file?
Well, there is an easy way of doing it in PHP. I'm at school right now so not much info on this. But make a .php file and place this in it.

<?php$ip = 'youriphere';$check = $_SERVER['REMOTE_ADDR'];if ($check == $ip) {//do whatever here} else {//show error here}?>
Save this as checkIP.php and upload to ftp.

Now make an index.php and place..
<?php include('checkIP.php'); ?>
I upload a file called htaccess.text then change it to .htaccess when on the server then edit it directly on the server with textmate or something.

In the file you put

# Allow only you to access
order deny, allow
deny from all
allow from [IP Address]


Active Member
Be careful though as most ISPs assign dynamic IPs so yours could change in the future unless you buy a fixed IP address from them.
:clap: pointless exercise TBH yesyoumay.

Instead create something like this ~

<?php if(isset($_POST['animal'])){
if($_POST['animal']=="thisisyourusernamechangeittowhateveryouwant" || $_POST['pass']=="thisisyourusernamechangeittowhateveryouwant"){
$_SESSION['cat']="Do you know this cat is in fact a monkey?";
header('Location: http://example/test/');

<form action="" method="post">
<input type="text" name="animal" />
<input type="password" name="pass" />
<button type="submit">Enter</button>

<?php }?>

Then add this to all text pages preferably in a a php include before any html ~
if(!isset($_SESSION['cat']) && $_SESSION['cat']!=="Do you know this cat is in fact a monkey?"){
header('Location: http://example.com/');

That way you've got a constant login form to a secure testing area with basic security. :)

If you get an errors as i just wrote that off the cuff let me know and I'll run it locally and fix them.

Yeah was going to say you may aswell just get a login form or something.
Imagen if you were staying away for a while with your laptop yet still wanted to go to your site, eh?
Screwed over then ain't ya :p

This is one of my friends websites. He has a login script etc. Could take a look at that, a lil more advanced than Jaz's obviously. (No intention to say your code won't work or anything, just incase he wanted to take a look, sorry, haha).


Active Member
Please not the above login script should only be used to secure basic data as it took me about 40seconds to write, I spent well over a day writing one for a CMS recently by far one of the best pieces of code I ever written.

Should have made that more clear so thanks for the reminder Ant. :)