Reply to Re: code works on one site, not on another????

Your name:

Reply:


Posted by J.O. Aho on 02/07/06 03:13

Bernie Woodham wrote:

> Yes, there are quite a bit of differences and I'm pretty much a novice at
> php. Here is the code; I include all the author's statements since he does
> have a copyright on it. But what should I be looking for?

The code is quite old and I guess the new site is using a lot newer version of
PHP.


> =================code==============================

> $iplist = array("234.765.123.0" , "62.00" , "539.765" ); // the list of
> banned IPs
>
> // $ip = getenv("REMOTE_ADDR"); // get the visitors IP address
$ip=$_SERVER['REMOTE_ADDR']; // current way to get visitors IP
> // echo "$ip";
> $found = false;
> foreach ($iplist as $value) { // scan the list
> if (strpos($ip, $value) === 0){
> $found = true;
> }
> }


>
> if ($found == true) {
> echo "top.location = \"http://www.google.com\";\n"; // page to divert to
> }

This seems to be part of a javascript, you could replace that with a usage of
header(). http://www.php.net/manual/en/function.header.php

If you use full ip's in the $iplist (xxx.yyy.zzz.qqq) then you could use

if(in_array($_SERVER['REMOTE_ADDR'],$iplist)) {
header("Location: http://www.google.com");
}

This is quite a lot shorter code to write and you don't have to mess with
javascript, which don't necessarily work the same way on all browsers.


//Aho

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация