Re: allowing access to php page by IP

From: Paul Van Schayck (newsgroups_at_meosource.com)
Date: 10/07/03


Date: 7 Oct 2003 14:36:12 -0000
To: php-general@lists.php.net

Hello,

awilliam@mdah.state.ms.us (Adam Williams) wrote
> I want to allow access to a php page but am not sure how I should
> verify the IP once I get it. I want to allow 10.8.4.* and 10.8.5.* to
> access a certain webpage and keep everyone else out. I have written
> code to figure out what someone's IP is, but am not sure about how I
> should verify whether the IP is in the range of 10.8.4.* or 10.8.5.*.
> Any suggestions? I was thinking of either using a regex (but I dunno
> regex so I'd have to learn it) to stip off the .* octect and then
> compare the rest of the IP and see if its either 10.8.4 or 10.8.5, or
> create a for loop and loop through 1-254 and cat it to the end of
> 10.8.4. and 10.8.5. and compare it to the IP they are coming from.
> Any suggestions on how I should do it?

Yes, bit basic but it should work. substr().
www.php.net/substr

$FirstPartIp = substr($ip,0,5);
if($FirstPartIp=='10.8.4' || $FirstPartIp=='10.8.5'){
    echo 'We have a local IP, continue!';
}else{
    echo 'Get out stupid hacker';}

Should work. An other way is exploding the IP by .
www.php.net/explode
$IpParts = explode('.',$ip);

$IpParts is now an array and you can check for the correct address.

Good luck,
Polleke



Relevant Pages

  • Re: Stupid Mistakes
    ... before the loop. ... ...oh, I see, it's a global set by findswfile. ... when you come back to this in six months' time) some searching. ... is a special character in a regex, ...
    (comp.lang.perl.misc)
  • Re: 2.6.16-rc4: known regressions
    ... either with a command line argument, or with just the early bootup initrd ... Is there a way to tell the kernel about which is the root device other ... a loop with one second delay. ... echo -n "Waiting for root device to appear" ...
    (Linux-Kernel)
  • Re: [PHP] 2 errors I can not understand
    ... echo is not a function. ... multiple args is probably insignificant, ... and super-long loop... ... function isprime ...
    (php.general)
  • RE: Reading contents of file
    ... keep the regex match as it is i.e. while ... But inside the loop when you a find a match and do relevant things, ... the existence of the matched pattern which is done by the help of bookref ... When I run the following script it goes to unending because it is ...
    (perl.beginners)
  • Re: Startup Script but wait for SQL to start
    ... In each case there is supposed to be a Username in the log file. ... @echo off ... if Errorlevel 1 goto Loop ... And it sucessfully starts up the Indexer. ...
    (microsoft.public.windows.server.general)