Forum Moderators: coopster
Search onn Google for block ip php script
[edited by: martinibuster at 3:09 am (utc) on Oct. 1, 2008]
[edit reason] Examplified. [/edit]
I would try the above code with <?php to start. I would also add your IP address so that you can check that the code works.
An explanation of the code:
1 <?php
2 $targetAddr = "202.46.129..*"; //yes is two dots
3 $targetAddr2 = "222.124.224.147" ;
4 if (ereg($targetAddr, $_SERVER['REMOTE_ADDR']) ¦¦
5 ereg($targetAddr2, $_SERVER['REMOTE_ADDR']))
6 { //remote address match, do something or don't do anything
7 header( 'Location: http://example.com) ;}
8 ?>
Lines 2 and 3- are variables (things that start with $ are variables) that are providing IP addresses. The $targetAddr is defining an address that is 202.46.129.anything as the .* means any character 0 or more times.
<note>
The . is any character, so they should be escaped when you want a literal . so \. is a literal .
* is 0 or more, so should not be used in places where you need characters. The + is 1 or more, so would be better used here.
</note>
Line 4- if statement. This statement is checking the two target address variables against the remote address provided to the server.
Line 7- if the remote addresses match then you redirect the browser to example.com.
Line 8- end of php.