0

I have migrated a 10 year old home-made forum written in php4 to a new Shared Hosting server running php5. I have found 3 errors, and I will be eternally grateful if you experts could help me solve them. They are the following:

1) Notice: Undefined index: HTTP_CLIENT_IP in /usr/local/pem/vhosts/144229/webspace/httpdocs/banner.php on line 268

2) Notice: Undefined index: HTTP_X_FORWARDED_FOR in /usr/local/pem/vhosts/144229/webspace/httpdocs/banner.php on line 269

The section there is the following:

// Patched function to detect REAL IP address ifit's valid
function getip(){
 global $HTTP_SERVER_VARS;
 if(validip($HTTP_SERVER_VARS['HTTP_CLIENT_IP'])) return $HTTP_SERVER_VARS['HTTP_CLIENT_IP'];
 elseif($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']!=""){
  $forwarded=str_replace(",","",$HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']);
  $forwarded_array=split(" ",$forwarded);
  foreach($forwarded_array as $value) if(validip($value)) return $value;
 }
 return $HTTP_SERVER_VARS['REMOTE_ADDR'];
}

The third error is: Fatal error: Call to undefined function sqlerr() in /usr/local/pem/vhosts/144229/webspace/httpdocs/banner.php on line 301

That section reads as follows:

function userlogin(){
 global $HTTP_SERVER_VARS,$SITE_ONLINE;
 unset($GLOBALS["CURUSER"]);
 $ip=getip();
 $nip=ip2long($ip);
 $res=mysql_query("SELECT * FROM bans WHERE $nip >= first AND $nip <= last") or sqlerr(__FILE__,__LINE__);
 if(mysql_num_rows($res) > 0){
  header("HTTP/1.0 403 Forbidden");
  print("<html><body><h1>403 Forbidden</h1>Unauthorized IP address.</body></html>\n");
  die;
 }

I'm utterly incompetent in php, but I inherited this issue from my Sysop, who's fighting cancer, and I have nobody else to turn to.

Thoughts and ideas on how to solve these errors? Thank you all !!!

FrK
  • 129
  • 4
  • sqlerr() is not a standard php function, therefore it's probably something custom, and whatever script is giving you the undefined function error isn't including the script that DOES define the function. – Marc B Mar 11 '15 at 19:24
  • 1
    Try `$_SERVER['REMOTE_ADDR']` instead of `HTTP_CLIENT_IP`. `$HTTP_SERVER_VARS;` has been removed. http://php.net/manual/en/reserved.variables.server.php @MarcB This is only partially a duplicate as it's dealing with specific PHP4 to PHP5 conversion issues. It's probably a duplicate of something else, but not what you marked. – Matt Mar 11 '15 at 19:31
  • mkaatman, your solution solved 99% of the problems. Now I can actually access my old forum, instead of getting a blank page with a few errors only. The old forum page looks terrible, plagued with dozens of "undefined index" and "undefined constant" errors. But it WORKS! Thank you, thank you, thank you !!! – FrK Mar 11 '15 at 20:10

0 Answers0