Re: Small Problem - could you help me, please?
| From: | Labunski | Date: | Thu, 18 Mar 2004 00:23:38 +0000 |
| Subject: | Re: Small Problem - could you help me, please? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180772@lists.php.net to get a copy of this message | ||
Thank you very much, it's working fine.
Lab.
"Jason Giangrande" <jason@giangrande.org> wrote in message
news:4058DE86.1060903@giangrande.org...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Labunski wrote:
> | $ip = getenv ("REMOTE_ADDR");
> |
> | function kick() {
> | $file_ip = file("log.txt");
> | foreach($file_ip as $value_ip ) {
> | $kick .= "$value_ip";
> | }
> | return $kick;
> | }
> | if ($ip == kick()){
> | echo "Sorry, the access is denied.";
> |
> | exit;
> | }
>
> In the function you seem to be appending all the ip addresses in the
> file to $kick. When you return kick it will hold all of the ips and not
> just and will therefore not be equal to $ip.
>
> You might want to try something like this:
>
> $ip = getenv ("REMOTE_ADDR");
>
> function kick($ip) {
> ~ $file_ip = file("log.txt") or die("Can't open file");
> ~ foreach ($file_ip as $value_ip) {
> $value_ip = preg_replace("/\n/", "", $value_ip);
> ~ if ($ip == $value_ip) {
> return true;
> }
> ~ }
> ~ return false;
> }
>
> if (kick($ip)) {
> echo "Sorry, the access is denied.";
> }
>
> It seems each ip address in the $file_ip has a new line on the end too,
> so you need to remove that before the current ip address in $ip will
> match anything that is in the file.
>
> Hope this helps.
>
> - --
> Jason Giangrande <jason@giangrande.org>
> http://www.giangrande.org
> http://www.dogsiview.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird -
> http://enigmail.mozdev.org
>
> iD8DBQFAWN6GjfevYzbk95IRAvx3AJ9jVbiSI0gyf50AkeJD63Z8LHT0ggCfQEqE
> RGunvEgTHkKJylmnywLxseM=
> =LJd1
> -----END PGP SIGNATURE-----