Re: [PHP] Restricting access using IPs
Liam, Not altogether happy with the suggestion below. It works - for now. A more generic solution might be to replace the hard-coded "9" with a call to strrchr() on the last 'dot' character position (minus one). Then it should work on any properly formed IP address. Thereafter parameterise the subnet address portion and things become mobile/re-usable. Regards, =dn > Oops, wrong variable. That should be: > > $substring = substr($REMOTE_ADDR,0,9); > > if ($substring == '192.168.0') > { > // you're in > } > > Michael > > > On Sat, 13 Jul 2002, Liam MacKenzie wrote: > > > > > If I enter 192.168.0.13 (My IP) it works, I'm allowed in and any other IP > > > isn't. > > > However, I need to grant access to this whole network, not just me. So I > > > need 192.168.0.* to be able to access it, everyone else should get "Access > > > Denied" > > > > > > So I need to know how to write this bit: > > > $localip = "192.168.0.13"; > > > so that it's the network, not just me. > > > > > > I tried these but they didn't work: > > > $localip = "192.168.0.0"; > > > $localip = "192.168.0.*"; > > > $localip = "192.168.0.0/24"; > > > > > > > > > Any other ideas? > > > > > > Cheers > > > > > > > > > > > > - Original Message - > > > From: "Jason Wong" <[EMAIL PROTECTED]> > > > To: <[EMAIL PROTECTED]> > > > Sent: Saturday, July 13, 2002 3:49 PM > > > Subject: Re: [PHP] Restricting access using IPs > > > > > > > > > > On Saturday 13 July 2002 13:10, Liam MacKenzie wrote: > > > > > Hey all, I'm looking to deny access to all IPs except those that fall > > > into > > > > > a specific IP range. 192.168.0.* in this case. > > > > > Am I missing something out of this code, it don't work too well ;-) > > > > > > > > HOW doesn't it work too well? It displays a picture of a naked guy instead > > > of > > > > the naked girl that you was expecting? > > > > > > > > > > > > > $localip = "192.168.0.13"; > > > > > if ($REMOTE_ADDR == $localip) { > > > > > ?> > > > > > > > > > > Allowed! > > > > > > > > > > > > > > } > > > > > else { > > > > > ?> > > > > > > > > > > Denied! > > > > > > > > > > > > > > } > > > > > > > > > > ?> > > > > > > > > > > > > -- > > > > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > > > > Open Source Software Systems Integrators > > > > * Web Design & Hosting * Internet & Intranet Applications Development * > > > > > > > > /* > > > > GOOD-NIGHT, everybody ... Now I have to go administer FIRST-AID to my > > > > pet LEISURE SUIT!! > > > > */ > > > > > > > > > > > > -- > > > > PHP General Mailing List (http://www.php.net/) > > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > n i n t i . c o m > php-python-perl-mysql-postgresql > > Michael Hall [EMAIL PROTECTED] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Restricting access using IPs
Oops, wrong variable. That should be: $substring = substr($REMOTE_ADDR,0,9); if ($substring == '192.168.0') { // you're in } Michael > On Sat, 13 Jul 2002, Liam MacKenzie wrote: > > > If I enter 192.168.0.13 (My IP) it works, I'm allowed in and any other IP > > isn't. > > However, I need to grant access to this whole network, not just me. So I > > need 192.168.0.* to be able to access it, everyone else should get "Access > > Denied" > > > > So I need to know how to write this bit: > > $localip = "192.168.0.13"; > > so that it's the network, not just me. > > > > I tried these but they didn't work: > > $localip = "192.168.0.0"; > > $localip = "192.168.0.*"; > > $localip = "192.168.0.0/24"; > > > > > > Any other ideas? > > > > Cheers > > > > > > > > - Original Message - > > From: "Jason Wong" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Saturday, July 13, 2002 3:49 PM > > Subject: Re: [PHP] Restricting access using IPs > > > > > > > On Saturday 13 July 2002 13:10, Liam MacKenzie wrote: > > > > Hey all, I'm looking to deny access to all IPs except those that fall > > into > > > > a specific IP range. 192.168.0.* in this case. > > > > Am I missing something out of this code, it don't work too well ;-) > > > > > > HOW doesn't it work too well? It displays a picture of a naked guy instead > > of > > > the naked girl that you was expecting? > > > > > > > > > > $localip = "192.168.0.13"; > > > > if ($REMOTE_ADDR == $localip) { > > > > ?> > > > > > > > > Allowed! > > > > > > > > > > > } > > > > else { > > > > ?> > > > > > > > > Denied! > > > > > > > > > > > } > > > > > > > > ?> > > > > > > > > > -- > > > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > > > Open Source Software Systems Integrators > > > * Web Design & Hosting * Internet & Intranet Applications Development * > > > > > > /* > > > GOOD-NIGHT, everybody ... Now I have to go administer FIRST-AID to my > > > pet LEISURE SUIT!! > > > */ > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > > > -- n i n t i . c o m php-python-perl-mysql-postgresql Michael Hall [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Restricting access using IPs
$substring = substr($localip,0,9); if ($substring == '192.168.0') { // you're in } On Sat, 13 Jul 2002, Liam MacKenzie wrote: > If I enter 192.168.0.13 (My IP) it works, I'm allowed in and any other IP > isn't. > However, I need to grant access to this whole network, not just me. So I > need 192.168.0.* to be able to access it, everyone else should get "Access > Denied" > > So I need to know how to write this bit: > $localip = "192.168.0.13"; > so that it's the network, not just me. > > I tried these but they didn't work: > $localip = "192.168.0.0"; > $localip = "192.168.0.*"; > $localip = "192.168.0.0/24"; > > > Any other ideas? > > Cheers > > > > ----- Original Message - > From: "Jason Wong" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Saturday, July 13, 2002 3:49 PM > Subject: Re: [PHP] Restricting access using IPs > > > > On Saturday 13 July 2002 13:10, Liam MacKenzie wrote: > > > Hey all, I'm looking to deny access to all IPs except those that fall > into > > > a specific IP range. 192.168.0.* in this case. > > > Am I missing something out of this code, it don't work too well ;-) > > > > HOW doesn't it work too well? It displays a picture of a naked guy instead > of > > the naked girl that you was expecting? > > > > > > > $localip = "192.168.0.13"; > > > if ($REMOTE_ADDR == $localip) { > > > ?> > > > > > > Allowed! > > > > > > > > } > > > else { > > > ?> > > > > > > Denied! > > > > > > > > } > > > > > > ?> > > > > > > -- > > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > > Open Source Software Systems Integrators > > * Web Design & Hosting * Internet & Intranet Applications Development * > > > > /* > > GOOD-NIGHT, everybody ... Now I have to go administer FIRST-AID to my > > pet LEISURE SUIT!! > > */ > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > -- n i n t i . c o m php-python-perl-mysql-postgresql Michael Hall [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Restricting access using IPs
On Saturday 13 July 2002 13:45, Liam MacKenzie wrote: > If I enter 192.168.0.13 (My IP) it works, I'm allowed in and any other IP > isn't. > However, I need to grant access to this whole network, not just me. So I > need 192.168.0.* to be able to access it, everyone else should get "Access > Denied" > > So I need to know how to write this bit: > $localip = "192.168.0.13"; > so that it's the network, not just me. > > I tried these but they didn't work: > $localip = "192.168.0.0"; > $localip = "192.168.0.*"; > $localip = "192.168.0.0/24"; In this particular case all you need to do is check that the ip address ($REMOTE_ADDR) begins with "192.168.0.". So look in the manual to see which of the string function(s) you need to perform this comparison (probably strstr()). -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Every improvement in communication makes the bore more terrible. -- Frank Moore Colby */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Restricting access using IPs
If I enter 192.168.0.13 (My IP) it works, I'm allowed in and any other IP isn't. However, I need to grant access to this whole network, not just me. So I need 192.168.0.* to be able to access it, everyone else should get "Access Denied" So I need to know how to write this bit: $localip = "192.168.0.13"; so that it's the network, not just me. I tried these but they didn't work: $localip = "192.168.0.0"; $localip = "192.168.0.*"; $localip = "192.168.0.0/24"; Any other ideas? Cheers - Original Message - From: "Jason Wong" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, July 13, 2002 3:49 PM Subject: Re: [PHP] Restricting access using IPs > On Saturday 13 July 2002 13:10, Liam MacKenzie wrote: > > Hey all, I'm looking to deny access to all IPs except those that fall into > > a specific IP range. 192.168.0.* in this case. > > Am I missing something out of this code, it don't work too well ;-) > > HOW doesn't it work too well? It displays a picture of a naked guy instead of > the naked girl that you was expecting? > > > > $localip = "192.168.0.13"; > > if ($REMOTE_ADDR == $localip) { > > ?> > > > > Allowed! > > > > > } > > else { > > ?> > > > > Denied! > > > > > } > > > > ?> > > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > > /* > GOOD-NIGHT, everybody ... Now I have to go administer FIRST-AID to my > pet LEISURE SUIT!! > */ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Restricting access using IPs
On Saturday 13 July 2002 13:10, Liam MacKenzie wrote: > Hey all, I'm looking to deny access to all IPs except those that fall into > a specific IP range. 192.168.0.* in this case. > Am I missing something out of this code, it don't work too well ;-) HOW doesn't it work too well? It displays a picture of a naked guy instead of the naked girl that you was expecting? > $localip = "192.168.0.13"; > if ($REMOTE_ADDR == $localip) { > ?> > > Allowed! > > } > else { > ?> > > Denied! > > } > > ?> -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* GOOD-NIGHT, everybody ... Now I have to go administer FIRST-AID to my pet LEISURE SUIT!! */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php