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


PHP IPAddress::getIP方法代码示例

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


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

示例1: logm

 /**
  * Log an array of category/message pairs
  */
 public static function logm($categoryMessagePairs)
 {
     $scribe = Z_CONFIG::$LOG_TO_SCRIBE;
     $cli = Z_Core::isCommandLine();
     // Scribe and CLI need additional info
     if ($scribe || $cli) {
         // Parse timestamp into date and milliseconds
         $ts = microtime(true);
         if (strpos($ts, '.') === false) {
             $ts .= '.';
         }
         list($ts, $msec) = explode('.', $ts);
         $date = new DateTime(date(DATE_RFC822, $ts));
         $date->setTimezone(new DateTimeZone(Z_CONFIG::$LOG_TIMEZONE));
         $date = $date->format('Y-m-d H:i:s') . '.' . str_pad($msec, 4, '0');
         // Get remote IP address
         if (!$cli) {
             $ipAddress = IPAddress::getIP();
         }
         // Get server hostname
         if ($scribe) {
             $host = gethostname();
             if (strpos($host, '.') !== false) {
                 $host = substr($host, 0, strpos($host, '.'));
             }
         }
     }
     $messages = array();
     foreach ($categoryMessagePairs as $pair) {
         // Scribe
         if ($scribe) {
             $messages[] = array('category' => $pair[0], 'message' => "{$date} [{$ipAddress}] [{$host}] " . $pair[1]);
         } else {
             if ($cli) {
                 $messages[] = array('category' => $pair[0], 'message' => $date . " " . $pair[1]);
             } else {
                 $messages[] = array('category' => $pair[0], 'message' => $pair[1]);
             }
         }
     }
     if (Z_CONFIG::$LOG_TO_SCRIBE) {
         self::logToScribe($messages);
     } else {
         self::logToErrorLog($messages);
     }
 }
开发者ID:selenus,项目名称:dataserver,代码行数:49,代码来源:log.inc.php

示例2: _handleFileRequest

 /**
  * Handle S3 request
  *
  * Permission-checking provided by items()
  */
 private function _handleFileRequest($item)
 {
     if (!$this->permissions->canAccess($this->objectLibraryID, 'files')) {
         $this->e403();
     }
     $this->allowMethods(array('HEAD', 'GET', 'POST', 'PATCH'));
     if (!$item->isAttachment()) {
         $this->e400("Item is not an attachment");
     }
     // File info for client sync
     //
     // Use of HEAD method is deprecated after 2.0.8/2.1b1 due to
     // compatibility problems with proxies and security software
     if ($this->method == 'HEAD' || $this->method == 'GET' && $this->fileMode == 'info') {
         $info = Zotero_S3::getLocalFileItemInfo($item);
         if (!$info) {
             $this->e404();
         }
         /*
         header("Last-Modified: " . gmdate('r', $info['uploaded']));
         header("Content-Type: " . $info['type']);
         */
         header("Content-Length: " . $info['size']);
         header("ETag: " . $info['hash']);
         header("X-Zotero-Filename: " . $info['filename']);
         header("X-Zotero-Modification-Time: " . $info['mtime']);
         header("X-Zotero-Compressed: " . ($info['zip'] ? 'Yes' : 'No'));
         header_remove("X-Powered-By");
     } else {
         if ($this->method == 'GET' || $this->method == 'POST' && $this->fileView) {
             if ($this->fileView) {
                 $info = Zotero_S3::getLocalFileItemInfo($item);
                 if (!$info) {
                     $this->e404();
                 }
                 // For zip files, redirect to files domain
                 if ($info['zip']) {
                     $url = Zotero_Attachments::getTemporaryURL($item, !empty($_GET['int']));
                     if (!$url) {
                         $this->e500();
                     }
                     header("Location: {$url}");
                     exit;
                 }
             }
             // For single files, redirect to S3
             $url = Zotero_S3::getDownloadURL($item, 60);
             if (!$url) {
                 $this->e404();
             }
             Zotero_S3::logDownload($item, $this->userID, IPAddress::getIP());
             header("Location: {$url}");
             exit;
         } else {
             if ($this->method == 'POST' || $this->method == 'PATCH') {
                 if (!$item->isImportedAttachment()) {
                     $this->e400("Cannot upload file for linked file/URL attachment item");
                 }
                 $libraryID = $item->libraryID;
                 $type = Zotero_Libraries::getType($libraryID);
                 if ($type == 'group') {
                     $groupID = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
                     $group = Zotero_Groups::get($groupID);
                     if (!$group->userCanEditFiles($this->userID)) {
                         $this->e403("You do not have file editing access");
                     }
                 } else {
                     $group = null;
                 }
                 // If not the client, require If-Match or If-None-Match
                 if (!$this->httpAuth) {
                     if (empty($_SERVER['HTTP_IF_MATCH']) && empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
                         $this->e428("If-Match/If-None-Match header not provided");
                     }
                     if (!empty($_SERVER['HTTP_IF_MATCH'])) {
                         if (!preg_match('/^"?([a-f0-9]{32})"?$/', $_SERVER['HTTP_IF_MATCH'], $matches)) {
                             $this->e400("Invalid ETag in If-Match header");
                         }
                         if (!$item->attachmentStorageHash) {
                             $info = Zotero_S3::getLocalFileItemInfo($item);
                             $this->e412("ETag set but file does not exist");
                         }
                         if ($item->attachmentStorageHash != $matches[1]) {
                             $this->e412("ETag does not match current version of file");
                         }
                     } else {
                         if ($_SERVER['HTTP_IF_NONE_MATCH'] != "*") {
                             $this->e400("Invalid value for If-None-Match header");
                         }
                         if ($this->attachmentStorageHash) {
                             $this->e412("If-None-Match: * set but file exists");
                         }
                     }
                 }
                 //
//.........这里部分代码省略.........
开发者ID:robinpaulson,项目名称:dataserver,代码行数:101,代码来源:ApiController.php

示例3: login

 public function login()
 {
     // TODO: Change to POST only
     if (empty($_REQUEST['username'])) {
         $this->error(403, 'NO_USER_NAME', "Username not provided");
     } else {
         if (empty($_REQUEST['password'])) {
             $this->error(403, 'NO_PASSWORD', "Password not provided");
         }
     }
     $username = $_REQUEST['username'];
     $password = $_REQUEST['password'];
     $authData = array('username' => $username, 'password' => $password);
     $userID = Zotero_Users::authenticate('password', $authData);
     if (!$userID) {
         StatsD::increment("sync.login.failure");
         if (isset($_SERVER['HTTP_X_ZOTERO_VERSION']) && $_SERVER['HTTP_X_ZOTERO_VERSION'] == "2.0b6") {
             die("Username/password not accepted");
         }
         $this->error(403, 'INVALID_LOGIN', "Username/password not accepted");
     }
     StatsD::increment("sync.login.success");
     $sessionID = md5($userID . uniqid(rand(), true) . $password);
     $ip = IPAddress::getIP();
     $sql = "INSERT INTO sessions (sessionID, userID, ipAddress)\n\t\t\t\t\tVALUES (?,?,INET_ATON(?))";
     Zotero_DB::query($sql, array($sessionID, $userID, $ip));
     Z_Core::$MC->set("syncSession_{$sessionID}", array('sessionID' => $sessionID, 'userID' => $userID), $this->sessionLifetime - 600);
     $this->responseXML->sessionID = $sessionID;
     $this->end();
 }
开发者ID:selenus,项目名称:dataserver,代码行数:30,代码来源:SyncController.php

示例4: logAccess

 public function logAccess()
 {
     if (!$this->id) {
         throw new Exception("Key not loaded");
     }
     $ip = IPAddress::getIP();
     // If we already logged access by this key from this IP address
     // in the last minute, don't do it again
     $cacheKey = "keyAccessLogged_" . $this->id . "_" . md5($ip);
     if (Z_Core::$MC->get($cacheKey)) {
         return;
     }
     try {
         $sql = "UPDATE `keys` SET lastUsed=NOW() WHERE keyID=?";
         Zotero_DB::query($sql, $this->id, 0, ['writeInReadMode' => true]);
         $sql = "REPLACE INTO keyAccessLog (keyID, ipAddress) VALUES (?, INET_ATON(?))";
         Zotero_DB::query($sql, [$this->id, $ip], 0, ['writeInReadMode' => true]);
     } catch (Exception $e) {
         error_log("WARNING: " . $e);
     }
     Z_Core::$MC->set($cacheKey, "1", 60);
 }
开发者ID:ergo70,项目名称:dataserver,代码行数:22,代码来源:Key.inc.php

示例5: logAccess

 public function logAccess()
 {
     if (!$this->id) {
         throw new Exception("Key not loaded");
     }
     $sql = "UPDATE `keys` SET lastUsed=NOW() WHERE keyID=?";
     Zotero_DB::query($sql, $this->id);
     $ip = IPAddress::getIP();
     $sql = "INSERT INTO keyAccessLog (keyID, ipAddress) VALUES (?, INET_ATON(?))";
     Zotero_DB::query($sql, array($this->id, $ip));
 }
开发者ID:robinpaulson,项目名称:dataserver,代码行数:11,代码来源:Key.inc.php


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