Hi people i really need a code in html that will block a persons ip address from going onto my site as i know some people who may like to get me banned from google by clicking the links so i would like to block these people i already know there ip address i just need a code that will stop there computer from viewing my website. thank you in advance.
need IP blocker on my site
| Code: |
| <?php
$ip = getenv("REMOTE_ADDR"); If ($ip=="255.255.255.255") //just a sample IP { echo "you're not allowed to visit my website"; } else { //your website sourcecode here } ?> |
| TomS wrote: | ||
|
Where do i put this code do i put it into my index page html code
You should put it on any page. And the extension of the file where you put it must be ".php".
you also have to make sure the host that it is hosted on supports php, if it is on frihost then it does
im sure there is a javascript solution that would work as well, but it would be easily disabled, also you might want to check your hosts admin page, because they might have a built in ip blocking mechanism
im sure there is a javascript solution that would work as well, but it would be easily disabled, also you might want to check your hosts admin page, because they might have a built in ip blocking mechanism
If you have many IP for baned you can use this script:
Sonam
P.S.
I think you can here on Frihost to use html extenstion, but I am not sure. Search and ask in suport forum.
| Code: |
| <?php
$ip = $_SERVER['REMOTE_ADDR']; // ip address $ban = array("255.255.255.255", "255.255.255.000", "127.0.0.1"); // baned ip address separated with coma // check is it ip in ban array foreach($ban as $key => $val){ if($val == $ip) { header("Location:http://www.google.com"); // redirect somewhere and bay bay exit; } } ?> |
Sonam
P.S.
I think you can here on Frihost to use html extenstion, but I am not sure. Search and ask in suport forum.
Thanx for all the help guys i found a really good site that does most of the work for you and that site is http://www.htmlbasix.com/blockusers.shtml
Create a new file and call it block.php.
Put the following code into it (thanks other users for helping to write the code).
At the top of every page you want these users to be blocked from, put in this code:
It has to go right at the top without a space or anything at the start or you will get an error.
You might want to change the way it blocks users by putting this code into block.php instead of the other:
Hope this helps.
Put the following code into it (thanks other users for helping to write the code).
| Code: |
|
<?php $ip = $_SERVER['REMOTE_ADDR']; // ip address $ban = array("255.255.255.255", "255.255.255.000", "127.0.0.1"); // baned ip address separated with coma // check is it ip in ban array foreach($ban as $key => $val){ if($val == $ip) { header("Location:http://www.google.com"); // redirect somewhere and bay bay exit; } } ?> |
At the top of every page you want these users to be blocked from, put in this code:
| Code: |
|
<?php include('block.php'); ?> |
It has to go right at the top without a space or anything at the start or you will get an error.
You might want to change the way it blocks users by putting this code into block.php instead of the other:
| Code: |
|
<?php $ip = $_SERVER['REMOTE_ADDR']; // ip address $ban = array("255.255.255.255", "255.255.255.000", "127.0.0.1"); // baned ip address separated with coma // check is it ip in ban array foreach($ban as $key => $val){ if($val == $ip) { ?> <script language="javascript"> alert('You have been banned from this site.') window.location="sorry.html" </script> <?php exit; } } ?> |
Hope this helps.
You can also use auto_prepend in the php.ini file.
| sonam wrote: | ||
If you have many IP for baned you can use this script:
Sonam P.S. I think you can here on Frihost to use html extenstion, but I am not sure. Search and ask in suport forum. |
This is easier:
| Code: |
|
<?php $ip = $_SERVER['REMOTE_ADDR']; // ip address $ban = array("255.255.255.255", "255.255.255.000", "127.0.0.1"); // baned ip address separated with coma // check is it ip in ban array if (in_array($ip, $ban)) { header("Location:http://www.google.com"); // redirect somewhere and bay bay exit; } ?> |
I plan to do this myself, but not with IP addresses but host names. Now, if anyone has a good demon graphic and demon laugh that I could put together as a page, I'd be ecstatic.
