当前位置: 首页>>代码示例>>PHP>>正文


PHP Piwik_Common::strlen方法代码示例

本文整理汇总了PHP中Piwik_Common::strlen方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Common::strlen方法的具体用法?PHP Piwik_Common::strlen怎么用?PHP Piwik_Common::strlen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Piwik_Common的用法示例。


在下文中一共展示了Piwik_Common::strlen方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: applyIPMask

 /**
  * Internal function to mask portions of the visitor IP address
  *
  * @param string $ip IP address in network address format
  * @param int $maskLength Number of octets to reset
  */
 public static function applyIPMask($ip, $maskLength)
 {
     $i = Piwik_Common::strlen($ip);
     if ($maskLength > $i) {
         $maskLength = $i;
     }
     while ($maskLength-- > 0) {
         $ip[--$i] = chr(0);
     }
     return $ip;
 }
开发者ID:0h546f6f78696342756e4e59,项目名称:piwik,代码行数:17,代码来源:AnonymizeIP.php

示例2: sendHttpRequestBy


//.........这里部分代码省略.........
             }
             // handle redirect
             if (preg_match('/^Location:\\s*(.+)/', rtrim($line, "\r\n"), $m)) {
                 if (is_resource($file)) {
                     @fclose($file);
                 }
                 @fclose($fsock);
                 // Successful 2xx vs Redirect 3xx
                 if ($status < 300) {
                     throw new Exception('Unexpected redirect to Location: ' . rtrim($line) . ' for status code ' . $status);
                 }
                 return self::sendHttpRequestBy($method, trim($m[1]), $timeout, $userAgent, $destinationPath, $file, $followDepth + 1, $acceptLanguage);
             }
             // save expected content length for later verification
             if (preg_match('/^Content-Length:\\s*(\\d+)/', $line, $m)) {
                 $contentLength = (int) $m[1];
             }
         }
         if (feof($fsock)) {
             throw new Exception('Unexpected end of transmission');
         }
         // process content/body
         $response = '';
         while (!feof($fsock)) {
             $line = fread($fsock, 8192);
             $streamMetaData = @stream_get_meta_data($fsock);
             if ($streamMetaData['timed_out']) {
                 if (is_resource($file)) {
                     @fclose($file);
                 }
                 @fclose($fsock);
                 throw new Exception('Timed out waiting for server response');
             }
             $fileLength += Piwik_Common::strlen($line);
             if (is_resource($file)) {
                 // save to file
                 fwrite($file, $line);
             } else {
                 // concatenate to response string
                 $response .= $line;
             }
         }
         // determine success or failure
         @fclose(@$fsock);
     } else {
         if ($method == 'fopen') {
             $response = false;
             // we make sure the request takes less than a few seconds to fail
             // we create a stream_context (works in php >= 5.2.1)
             // we also set the socket_timeout (for php < 5.2.1)
             $default_socket_timeout = @ini_get('default_socket_timeout');
             @ini_set('default_socket_timeout', $timeout);
             $ctx = null;
             if (function_exists('stream_context_create')) {
                 $stream_options = array('http' => array('header' => 'User-Agent: ' . $userAgent . "\r\n" . ($acceptLanguage ? $acceptLanguage . "\r\n" : '') . $xff . "\r\n" . $via . "\r\n", 'max_redirects' => 5, 'timeout' => $timeout));
                 if (!empty($proxyHost) && !empty($proxyPort)) {
                     $stream_options['http']['proxy'] = 'tcp://' . $proxyHost . ':' . $proxyPort;
                     $stream_options['http']['request_fulluri'] = true;
                     // required by squid proxy
                     if (!empty($proxyUser) && !empty($proxyPassword)) {
                         $stream_options['http']['header'] .= 'Proxy-Authorization: Basic ' . base64_encode("{$proxyUser}:{$proxyPassword}") . "\r\n";
                     }
                 }
                 $ctx = stream_context_create($stream_options);
             }
             // save to file
开发者ID:nomoto-ubicast,项目名称:piwik,代码行数:67,代码来源:Http.php

示例3: isValidHost

 /**
  * Validate "Host" (untrusted user input)
  *
  * @param string $host         Contents of Host: header from Request
  * @param array  $trustedHosts An array of trusted hosts
  *
  * @return boolean True if valid; false otherwise
  */
 public static function isValidHost($host, $trustedHosts)
 {
     // Only punctuation we allow is '[', ']', ':', '.' and '-'
     $hostLength = Piwik_Common::strlen($host);
     if ($hostLength !== strcspn($host, '`~!@#$%^&*()_+={}\\|;"\'<>,?/ ')) {
         return false;
     }
     $untrustedHost = Piwik_Common::mb_strtolower($host);
     $hostRegex = Piwik_Common::mb_strtolower(str_replace('.', '\\.', '/(^|.)' . implode('|', $trustedHosts) . '(:[0-9]+)?$/'));
     return 0 !== preg_match($hostRegex, rtrim($untrustedHost, '.'));
 }
开发者ID:nnnnathann,项目名称:piwik,代码行数:19,代码来源:Url.php

示例4: isIpInRange

 /**
  * Determines if an IP address is in a specified IP address range.
  *
  * An IPv4-mapped address should be range checked with an IPv4-mapped address range.
  *
  * @param string $ip IP address in network address format
  * @param array $ipRanges List of IP address ranges
  * @return bool True if in any of the specified IP address ranges; else false.
  */
 public static function isIpInRange($ip, $ipRanges)
 {
     $ipLen = Piwik_Common::strlen($ip);
     if (empty($ip) || empty($ipRanges) || $ipLen != 4 && $ipLen != 16) {
         return false;
     }
     foreach ($ipRanges as $range) {
         if (is_array($range)) {
             // already split into low/high IP addresses
             $range[0] = self::P2N($range[0]);
             $range[1] = self::P2N($range[1]);
         } else {
             // expect CIDR format but handle some variations
             $range = self::getIpsForRange($range);
         }
         if ($range === false) {
             continue;
         }
         $low = $range[0];
         $high = $range[1];
         if (Piwik_Common::strlen($low) != $ipLen) {
             continue;
         }
         // binary-safe string comparison
         if ($ip >= $low && $ip <= $high) {
             return true;
         }
     }
     return false;
 }
开发者ID:neolf,项目名称:PIWIK4MOBILE,代码行数:39,代码来源:IP.php

示例5: isValidHost

 /**
  * Validate "Host" (untrusted user input)
  *
  * @param string|false $host Contents of Host: header from Request. If false, gets the
  *                           value from the request.
  *
  * @return boolean True if valid; false otherwise
  */
 public static function isValidHost($host = false)
 {
     // only do trusted host check if it's enabled
     if (isset(Piwik_Config::getInstance()->General['enable_trusted_host_check']) && Piwik_Config::getInstance()->General['enable_trusted_host_check'] == 0) {
         return true;
     }
     if ($host === false) {
         $host = $_SERVER['HTTP_HOST'];
         if (empty($host)) {
             return true;
         }
     }
     // if host is in hardcoded whitelist, assume it's valid
     if (in_array($host, self::$alwaysTrustedHosts)) {
         return true;
     }
     $trustedHosts = @Piwik_Config::getInstance()->General['trusted_hosts'];
     // if no trusted hosts, just assume it's valid
     if (empty($trustedHosts)) {
         self::saveTrustedHostnameInConfig($host);
         return true;
     }
     // Only punctuation we allow is '[', ']', ':', '.' and '-'
     $hostLength = Piwik_Common::strlen($host);
     if ($hostLength !== strcspn($host, '`~!@#$%^&*()_+={}\\|;"\'<>,?/ ')) {
         return false;
     }
     foreach ($trustedHosts as &$trustedHost) {
         $trustedHost = preg_quote($trustedHost);
     }
     $untrustedHost = Piwik_Common::mb_strtolower($host);
     $untrustedHost = rtrim($untrustedHost, '.');
     $hostRegex = Piwik_Common::mb_strtolower('/(^|.)' . implode('|', $trustedHosts) . '$/');
     $result = preg_match($hostRegex, $untrustedHost);
     //		var_dump($hostRegex);var_dump($untrustedHost);var_dump($result);
     return 0 !== $result;
 }
开发者ID:nomoto-ubicast,项目名称:piwik,代码行数:45,代码来源:Url.php


注:本文中的Piwik_Common::strlen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。