PHP Only Allow My IP

[FONT=“Georgia”]Hi, could anyone help me with writing a code for how to only allow my IP address into the website and all others get an error message or get redirected!

Thanks In Advanced[/FONT]

Hi,

Could u be more elaborative please ?

Well the code is very simple.

U first define your ip, and let it pass.



$myip = "Your IP";
$location = "location where ever u want to redirect";

if($_SERVER['REMOTE_ADDR'] != $myip)
{
header("Location: $location");
}
else
{
//it's me let me pass in

}

While there are numerous way, u can also restrict users by .htaccess too.

I meant my ip lets me view the page but any other ip is not allowed!

Then I think the code I provided should work fine.

Ive Put In The Code, Can Someone Try And Browse My Website http:// comptuts . co . cc

I put spaces, please remove.

This is the message I’ve got when I tried to access that.

This webpage has a redirect loop.

The webpage at http://comptuts.co.cc/index.php has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.

Try to redirect to any other page instead of index, as your index page is redirecting to same page and that page is redirecting back to index and making it a loop.

make sure to call exit() after sending a redirect header. Otherwise, people can still view the page.

Thanks @crmalibu and @cools_sonu