Errore "Access to undeclared static property"

  • Creatore Discussione Creatore Discussione Furion
  • Data di inizio Data di inizio

Furion

Utente Attivo
26 Ago 2013
32
0
0
Salve a tutti, da un pò di tempo sto utilizzando uno script per ricavarmi gli ip, fino ad oggi ha funzionato tranquillamente, da oggi invece esce questo errore: Access to undeclared static property: IpUser::$ip in *percorso file* on line 46

lo script è questo:

PHP:
<?php 

class IpUser 
{ 
 public function get_ip_address() { 
  // check for shared internet/ISP IP 
  if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP'])) 
   return $_SERVER['HTTP_CLIENT_IP']; 

  // check for IPs passing through proxies 
  if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
   // check if multiple ips exist in var 
    $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); 
    foreach ($iplist as $ip) { 
     if ($this->validate_ip($ip)) 
      return $ip; 
    } 
   } 
  if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED'])) 
   return $_SERVER['HTTP_X_FORWARDED']; 
  if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) 
   return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; 
  if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR'])) 
   return $_SERVER['HTTP_FORWARDED_FOR']; 
  if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED'])) 
   return $_SERVER['HTTP_FORWARDED']; 

  // return unreliable ip since all else failed 
  return $_SERVER['REMOTE_ADDR']; 
 } 

 /** 
  * Ensures an ip address is both a valid IP and does not fall within 
  * a private network range. 
  * 
  * @access public 
  * @param string $ip 
  */ 
 public function validate_ip($ip) { 
     if (filter_var($ip, FILTER_VALIDATE_IP,  
                         FILTER_FLAG_IPV4 |  
                         FILTER_FLAG_IPV6 | 
                         FILTER_FLAG_NO_PRIV_RANGE |  
                         FILTER_FLAG_NO_RES_RANGE) === false) 
         return false; 
     self::$ip = $ip; 
     return true; 
 } 
} 
?>

e lo richiamo così:
PHP:
$tmp = new IpUser(); 
$ip = $tmp->get_ip_address();

idee? :confused:
Grazie anticipatamente!

P.S: oggi il mio host ha attivato di default CloudFlare, potrebbe dipendere da quello? perchè è l'unica modifica fatta al mio sito...
 
Manca questa proprietà
PHP:
self::$ip = $ip;

Prova ad aggiungerla
PHP:
class IpUser  
{  
 public static $ip;
 public function get_ip_address() {  
  // check for shared internet/ISP IP  
  if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP']))  
   return $_SERVER['HTTP_CLIENT_IP'];  

  // check for IPs passing through proxies  
  if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {  
   // check if multiple ips exist in var  
    $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);  
    foreach ($iplist as $ip) {  
     if ($this->validate_ip($ip))  
      return $ip;  
    }  
   }  
  if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED']))  
   return $_SERVER['HTTP_X_FORWARDED'];  
  if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))  
   return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];  
  if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR']))  
   return $_SERVER['HTTP_FORWARDED_FOR'];  
  if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED']))  
   return $_SERVER['HTTP_FORWARDED'];  

  // return unreliable ip since all else failed  
  return $_SERVER['REMOTE_ADDR'];  
 }  

 /**  
  * Ensures an ip address is both a valid IP and does not fall within  
  * a private network range.  
  *  
  * @access public  
  * @param string $ip  
  */  
 public function validate_ip($ip) {  
     if (filter_var($ip, FILTER_VALIDATE_IP,   
                         FILTER_FLAG_IPV4 |   
                         FILTER_FLAG_IPV6 |  
                         FILTER_FLAG_NO_PRIV_RANGE |   
                         FILTER_FLAG_NO_RES_RANGE) === false)  
         return false;  
     self::$ip = $ip;  
     return true;  
 }  
}
 

Discussioni simili