[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/include/inc_ext/bad-behavior/bad-behavior/ -> functions.inc.php (source)

   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              }
  50          }
  51      } else {
  52          @list($ip, $mask) = explode('/', $cidr);
  53          if (!$mask) $mask = 32;
  54          $mask = pow(2,32) - pow(2, (32 - $mask));
  55          $output = ((ip2long($addr) & $mask) == (ip2long($ip) & $mask));
  56      }
  57      return $output;
  58  }
  59  
  60  // Obtain all the HTTP headers.
  61  // NB: on PHP-CGI we have to fake it out a bit, since we can't get the REAL
  62  // headers. Run PHP as Apache 2.0 module if possible for best results.
  63  function bb2_load_headers() {
  64      if (!is_callable('getallheaders')) {
  65          $headers = array();
  66          foreach ($_SERVER as $h => $v)
  67              if (preg_match('/HTTP_(.+)/', $h, $hp))
  68                  $headers[str_replace("_", "-", uc_all($hp[1]))] = $v;
  69      } else {
  70          $headers = getallheaders();
  71      }
  72      return $headers;
  73  }
  74  
  75  ?>


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7