"Fossies" - the Fresh Open Source Software Archive

Member "bad-behavior/bad-behavior/functions.inc.php" (22 Feb 2012, 2197 Bytes) of package /linux/www/bad-behavior.2.2.24.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php if (!defined('BB2_CORE')) die("I said no cheating!");
    2 
    3 // Miscellaneous helper functions.
    4 
    5 // Quick and dirty check for an IPv6 address
    6 function is_ipv6($address) {
    7     return (strpos($address, ":")) ? TRUE : FALSE;
    8 }
    9 
   10 // stripos() needed because stripos is only present on PHP 5
   11 if (!function_exists('stripos')) {
   12     function stripos($haystack,$needle,$offset = 0) {
   13         return(strpos(strtolower($haystack),strtolower($needle),$offset));
   14     }
   15 }
   16 
   17 // str_split() needed because str_split is only present on PHP 5
   18 if (!function_exists('str_split')) {
   19     function str_split($string, $split_length=1)
   20     {
   21         if ($split_length < 1) {
   22             return false;
   23         }
   24 
   25         for ($pos=0, $chunks = array(); $pos < strlen($string); $pos+=$split_length) {
   26             $chunks[] = substr($string, $pos, $split_length);
   27         }
   28         return $chunks;
   29     }
   30 }
   31 
   32 // Convert a string to mixed-case on word boundaries.
   33 function uc_all($string) {
   34     $temp = preg_split('/(\W)/', str_replace("_", "-", $string), -1, PREG_SPLIT_DELIM_CAPTURE);
   35     foreach ($temp as $key=>$word) {
   36         $temp[$key] = ucfirst(strtolower($word));
   37     }
   38     return join ('', $temp);
   39 }
   40 
   41 // Determine if an IP address resides in a CIDR netblock or netblocks.
   42 function match_cidr($addr, $cidr) {
   43     $output = false;
   44 
   45     if (is_array($cidr)) {
   46         foreach ($cidr as $cidrlet) {
   47             if (match_cidr($addr, $cidrlet)) {
   48                 $output = true;
   49                 break;
   50             }
   51         }
   52     } else {
   53         @list($ip, $mask) = explode('/', $cidr);
   54         if (!$mask) $mask = 32;
   55         $mask = pow(2,32) - pow(2, (32 - $mask));
   56         $output = ((ip2long($addr) & $mask) == (ip2long($ip) & $mask));
   57     }
   58     return $output;
   59 }
   60 
   61 // Determine if an IP address is reserved by RFC 1918.
   62 function is_rfc1918($addr) {
   63     return match_cidr($addr, array("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"));
   64 }
   65 // Obtain all the HTTP headers.
   66 // NB: on PHP-CGI we have to fake it out a bit, since we can't get the REAL
   67 // headers. Run PHP as Apache 2.0 module if possible for best results.
   68 function bb2_load_headers() {
   69     if (!is_callable('getallheaders')) {
   70         $headers = array();
   71         foreach ($_SERVER as $h => $v)
   72             if (preg_match('/HTTP_(.+)/', $h, $hp))
   73                 $headers[str_replace("_", "-", uc_all($hp[1]))] = $v;
   74     } else {
   75         $headers = getallheaders();
   76     }
   77     return $headers;
   78 }