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


PHP OC_Request::getRemoteAddress方法代码示例

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


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

示例1: testGetRemoteAddress

 public function testGetRemoteAddress()
 {
     $_SERVER['REMOTE_ADDR'] = '10.0.0.2';
     $_SERVER['HTTP_X_FORWARDED'] = '10.4.0.5, 10.4.0.4';
     $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.0.233';
     // Without having specified a trusted remote address
     $this->assertEquals('10.0.0.2', OC_Request::getRemoteAddress());
     // With specifying a trusted remote address but no trusted header
     OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.0.0.2'));
     $this->assertEquals('10.0.0.2', OC_Request::getRemoteAddress());
     // With specifying a trusted remote address and trusted headers
     OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.0.0.2'));
     OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_X_FORWARDED'));
     $this->assertEquals('10.4.0.5', OC_Request::getRemoteAddress());
     OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED'));
     $this->assertEquals('192.168.0.233', OC_Request::getRemoteAddress());
     // With specifying multiple trusted remote addresses and trusted headers
     OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.3.4.2', '10.0.0.2', '127.0.3.3'));
     OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_X_FORWARDED'));
     $this->assertEquals('10.4.0.5', OC_Request::getRemoteAddress());
     OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED'));
     $this->assertEquals('192.168.0.233', OC_Request::getRemoteAddress());
 }
开发者ID:Romua1d,项目名称:core,代码行数:23,代码来源:request.php

示例2: write

 /**
  * write a message in the log
  * @param string $app
  * @param string $message
  * @param int $level
  */
 public static function write($app, $message, $level)
 {
     $minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
     if ($level >= $minLevel) {
         // default to ISO8601
         $format = OC_Config::getValue('logdateformat', 'c');
         $logtimezone = OC_Config::getValue("logtimezone", 'UTC');
         try {
             $timezone = new DateTimeZone($logtimezone);
         } catch (Exception $e) {
             $timezone = new DateTimeZone('UTC');
         }
         $time = new DateTime(null, $timezone);
         $reqId = \OC_Request::getRequestID();
         $remoteAddr = \OC_Request::getRemoteAddress();
         // remove username/passwords from URLs before writing the to the log file
         $time = $time->format($format);
         if ($minLevel == OC_Log::DEBUG) {
             $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '--';
             $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '--';
             $entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time', 'method', 'url');
         } else {
             $entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time');
         }
         $entry = json_encode($entry);
         $handle = @fopen(self::$logFile, 'a');
         @chmod(self::$logFile, 0640);
         if ($handle) {
             fwrite($handle, $entry . "\n");
             fclose($handle);
         } else {
             // Fall back to error_log
             error_log($entry);
         }
     }
 }
开发者ID:Romua1d,项目名称:core,代码行数:42,代码来源:owncloud.php

示例3: printExceptionErrorPage

 /**
  * print error page using Exception details
  * @param Exception $exception
  */
 public static function printExceptionErrorPage(Exception $exception)
 {
     $content = new \OC_Template('', 'exception', 'error', false);
     $content->assign('errorMsg', $exception->getMessage());
     $content->assign('errorCode', $exception->getCode());
     $content->assign('file', $exception->getFile());
     $content->assign('line', $exception->getLine());
     $content->assign('trace', $exception->getTraceAsString());
     $content->assign('debugMode', defined('DEBUG') && DEBUG === true);
     $content->assign('remoteAddr', OC_Request::getRemoteAddress());
     $content->assign('requestID', OC_Request::getRequestID());
     $content->printPage();
     die;
 }
开发者ID:kebenxiaoming,项目名称:owncloudRedis,代码行数:18,代码来源:template.php


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