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


PHP UserUtil::getIpAddress方法代码示例

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


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

示例1: create

 /**
  * @see SessionFactory::create()
  */
 public function create()
 {
     // create new session hash
     $sessionID = StringUtil::getRandomID();
     // check cookies for userID & password
     require_once WCF_DIR . 'lib/system/auth/UserAuth.class.php';
     $user = UserAuth::getInstance()->loginAutomatically(true, $this->userClassName);
     if ($user === null) {
         // no valid user found
         // create guest user
         $user = new $this->guestClassName();
     }
     // update user session
     $user->update();
     // get spider information
     $spider = $this->isSpider(UserUtil::getUserAgent());
     if ($user->userID != 0) {
         // user is no guest
         // delete all other sessions of this user
         Session::deleteSessions($user->userID, true, false);
     }
     $requestMethod = !empty($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
     // insert session into database
     $sql = "INSERT INTO \twcf" . WCF_N . "_session\n\t\t\t\t\t(sessionID, packageID, userID, ipAddress, userAgent,\n\t\t\t\t\tlastActivityTime, requestURI, requestMethod,\n\t\t\t\t\tusername" . ($spider ? ", spiderID" : "") . ")\n\t\t\tVALUES\t\t('" . $sessionID . "',\n\t\t\t\t\t" . PACKAGE_ID . ",\n\t\t\t\t\t" . $user->userID . ",\n\t\t\t\t\t'" . escapeString(UserUtil::getIpAddress()) . "',\n\t\t\t\t\t'" . escapeString(UserUtil::getUserAgent()) . "',\n\t\t\t\t\t" . TIME_NOW . ",\n\t\t\t\t\t'" . escapeString(UserUtil::getRequestURI()) . "',\n\t\t\t\t\t'" . escapeString($requestMethod) . "',\n\t\t\t\t\t'" . ($spider ? escapeString($spider['spiderName']) : escapeString($user->username)) . "'\n\t\t\t\t\t" . ($spider ? ", " . $spider['spiderID'] : "") . ")";
     WCF::getDB()->sendQuery($sql);
     // save user data
     $serializedUserData = '';
     if (ENABLE_SESSION_DATA_CACHE && get_class(WCF::getCache()->getCacheSource()) == 'MemcacheCacheSource') {
         require_once WCF_DIR . 'lib/system/cache/source/MemcacheAdapter.class.php';
         MemcacheAdapter::getInstance()->getMemcache()->set('session_userdata_-' . $sessionID, $user);
     } else {
         $serializedUserData = serialize($user);
         try {
             $sql = "INSERT INTO \twcf" . WCF_N . "_session_data\n\t\t\t\t\t\t\t(sessionID, userData)\n\t\t\t\t\tVALUES \t\t('" . $sessionID . "',\n\t\t\t\t\t\t\t'" . escapeString($serializedUserData) . "')";
             WCF::getDB()->sendQuery($sql);
         } catch (DatabaseException $e) {
             // horizon update workaround
             $sql = "UPDATE \twcf" . WCF_N . "_session\n\t\t\t\t\tSET\tuserData = '" . escapeString($serializedUserData) . "'\n\t\t\t\t\tWHERE\tsessionID = '" . $sessionID . "'";
             WCF::getDB()->sendQuery($sql);
         }
     }
     // return new session object
     return new $this->sessionClassName(null, array('sessionID' => $sessionID, 'packageID' => PACKAGE_ID, 'userID' => $user->userID, 'ipAddress' => UserUtil::getIpAddress(), 'userAgent' => UserUtil::getUserAgent(), 'lastActivityTime' => TIME_NOW, 'requestURI' => UserUtil::getRequestURI(), 'requestMethod' => $requestMethod, 'userData' => $serializedUserData, 'sessionVariables' => '', 'username' => $spider ? $spider['spiderName'] : $user->username, 'spiderID' => $spider ? $spider['spiderID'] : 0, 'isNew' => true));
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:47,代码来源:CookieSessionFactory.class.php

示例2: verify

 /**
  * Verifies the challenge and response with the recaptcha verify server.
  * 
  * Parts of this function are taken from lib/util/FileUtil.class.php from the
  * WoltLab Community Framework which is licensed unter the
  * GNU Lesser General Public License <http://www.gnu.org/licenses/lgpl.html>.
  * More on <http://www.woltlab.com/> and <http://community.woltlab.com/>.
  * 
  * @param	string	$challenge
  * @param	string	$response
  * @return	string
  */
 protected static function verify($challenge, $response)
 {
     // get proxy
     $options = array();
     if (PROXY_SERVER_HTTP) {
         $options['http']['proxy'] = PROXY_SERVER_HTTP;
     }
     require_once WCF_DIR . 'lib/system/io/RemoteFile.class.php';
     $remoteFile = new RemoteFile(self::RECAPTCHA_HOST, self::RECAPTCHA_PORT, 30, $options);
     // the file to read.
     if (!isset($remoteFile)) {
         return self::ERROR_NOT_REACHABLE;
     }
     // build post string
     $postData = 'privatekey=' . urlencode(self::getPrivateKey());
     $postData .= '&remoteip=' . urlencode(UserUtil::getIpAddress());
     $postData .= '&challenge=' . urlencode($challenge);
     $postData .= '&response=' . urlencode($response);
     // build and send the http request.
     $request = "POST " . self::RECAPTCHA_PATH . " HTTP/1.0\r\n";
     $request .= "User-Agent: HTTP.PHP (info.codingcorner.wcf.recaptcha; WoltLab Community Framework/" . WCF_VERSION . "; " . WCF::getLanguage()->getLanguageCode() . ")\r\n";
     $request .= "Accept: */*\r\n";
     $request .= "Accept-Language: " . WCF::getLanguage()->getLanguageCode() . "\r\n";
     $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n";
     $request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
     $request .= "Content-Length: " . strlen($postData) . "\r\n";
     $request .= "Connection: Close\r\n\r\n";
     $request .= $postData;
     $remoteFile->puts($request);
     $waiting = true;
     $readResponse = array();
     $reCaptchaResponse = array();
     // read http response.
     while (!$remoteFile->eof()) {
         $readResponse[] = $remoteFile->gets();
         // look if we are done with transferring the requested file.
         if ($waiting) {
             if (rtrim($readResponse[count($readResponse) - 1]) == '') {
                 $waiting = false;
             }
         } else {
             // look if the webserver sent an error http statuscode
             // This has still to be checked if really sufficient!
             $arrayHeader = array('201', '301', '302', '303', '307', '404');
             foreach ($arrayHeader as $code) {
                 $error = strpos($readResponse[0], $code);
             }
             if ($error !== false) {
                 return self::ERROR_NOT_REACHABLE;
             }
             // write to the target system.
             $reCaptchaResponse[] = $readResponse[count($readResponse) - 1];
         }
     }
     if (StringUtil::trim($reCaptchaResponse[0]) == "true") {
         return self::VALID_ANSWER;
     } else {
         return StringUtil::trim($reCaptchaResponse[1]);
     }
 }
开发者ID:RouL,项目名称:reCAPTCHA_Support,代码行数:72,代码来源:ReCaptchaUtil.class.php

示例3: getExistingSpiderSession

 /**
  * Finds an existing session of a search spider.
  * 
  * @param 	integer		$spiderID
  * @return	CookieSession
  */
 protected function getExistingSpiderSession($spiderID)
 {
     if (!ENABLE_SESSION_DATA_CACHE || get_class(WCF::getCache()->getCacheSource()) != 'MemcacheCacheSource') {
         $sql = "SELECT \t\tsession_data.*, session.* \n\t\t\t\tFROM \t\twcf" . WCF_N . "_session session\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_session_data session_data\n\t\t\t\tON\t\t(session_data.sessionID = session.sessionID)\n\t\t\t\tWHERE \t\tsession.spiderID = '" . escapeString($spiderID) . "'\n\t\t\t\t\t\tAND session.userID = 0";
     } else {
         $sql = "SELECT \t\t* \n\t\t\t\tFROM \t\twcf" . WCF_N . "_session\n\t\t\t\tWHERE \t\tspiderID = '" . escapeString($spiderID) . "'\n\t\t\t\t\t\tAND userID = 0";
     }
     $row = WCF::getDB()->getFirstRow($sql);
     if (!empty($row['sessionID'])) {
         // fix session validation
         $row['ipAddress'] = UserUtil::getIpAddress();
         $row['userAgent'] = UserUtil::getUserAgent();
         // return session object
         return new $this->sessionClassName(null, $row);
     }
     return null;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:23,代码来源:CookieSessionFactory.class.php

示例4: validate

 /**
  * Validates the ip address or the user agent of this session.
  * 
  * @return 	boolean
  */
 protected function validate()
 {
     if (SESSION_VALIDATE_USER_AGENT && $this->userAgent != UserUtil::getUserAgent()) {
         return false;
     }
     if (SESSION_VALIDATE_IP_ADDRESS > 0) {
         if (SESSION_VALIDATE_IP_ADDRESS == 4) {
             if ($this->ipAddress != UserUtil::getIpAddress()) {
                 return false;
             }
         } else {
             // skip validation for IPv6
             if (strpos($this->ipAddress, '.') !== false) {
                 // validate blocks
                 $oldIpAddressBlocks = explode('.', $this->ipAddress);
                 $newIpAddressBlocks = explode('.', UserUtil::getIpAddress());
                 for ($i = 0; $i < SESSION_VALIDATE_IP_ADDRESS; $i++) {
                     if (!isset($oldIpAddressBlocks[$i]) || !isset($newIpAddressBlocks[$i]) || $oldIpAddressBlocks[$i] != $newIpAddressBlocks[$i]) {
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:31,代码来源:Session.class.php

示例5: create

 /**
  * Creates a new session.
  * 
  * Generates a new session hash, inserts the new session into database
  * and returns the object of the created session. 
  * 
  * @return 	 Session 	$session
  */
 public function create()
 {
     // create new session hash
     $sessionID = StringUtil::getRandomID();
     // get user automatically
     if (!defined('NO_IMPORTS')) {
         require_once WCF_DIR . 'lib/system/auth/UserAuth.class.php';
     }
     $user = UserAuth::getInstance()->loginAutomatically();
     // create user
     if ($user === null) {
         // no valid user found
         // create guest user
         $user = new $this->userClassName();
     }
     // update user session
     $user->update();
     // insert session into database
     $requestMethod = !empty($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
     $sql = "INSERT INTO \twcf" . WCF_N . "_acp_session\n\t\t\t\t\t(sessionID, packageID, userID, ipAddress, userAgent, lastActivityTime, requestURI, requestMethod)\n\t\t\tVALUES \t\t('" . $sessionID . "',\n\t\t\t\t\t" . PACKAGE_ID . ",\n\t\t\t\t\t" . $user->userID . ",\n\t\t\t\t\t'" . escapeString(UserUtil::getIpAddress()) . "',\n\t\t\t\t\t'" . escapeString(UserUtil::getUserAgent()) . "',\n\t\t\t\t\t" . TIME_NOW . ",\n\t\t\t\t\t'" . escapeString(UserUtil::getRequestURI()) . "',\n\t\t\t\t\t'" . escapeString($requestMethod) . "')";
     WCF::getDB()->sendQuery($sql);
     // save user data
     $serializedUserData = '';
     if (ENABLE_SESSION_DATA_CACHE && get_class(WCF::getCache()->getCacheSource()) == 'MemcacheCacheSource') {
         require_once WCF_DIR . 'lib/system/cache/source/MemcacheAdapter.class.php';
         MemcacheAdapter::getInstance()->getMemcache()->set('acp_session_userdata_' . $sessionID, $user);
     } else {
         $serializedUserData = serialize($user);
         try {
             $sql = "INSERT INTO \twcf" . WCF_N . "_acp_session_data\n\t\t\t\t\t\t\t(sessionID, userData)\n\t\t\t\t\tVALUES \t\t('" . $sessionID . "',\n\t\t\t\t\t\t\t'" . escapeString($serializedUserData) . "')";
             WCF::getDB()->sendQuery($sql);
         } catch (DatabaseException $e) {
             // horizon update workaround
             $sql = "UPDATE \twcf" . WCF_N . "_acp_session\n\t\t\t\t\tSET\tuserData = '" . escapeString($serializedUserData) . "'\n\t\t\t\t\tWHERE\tsessionID = '" . $sessionID . "'";
             WCF::getDB()->sendQuery($sql);
         }
     }
     // return new session object
     return new $this->sessionClassName(null, array('sessionID' => $sessionID, 'packageID' => PACKAGE_ID, 'ipAddress' => UserUtil::getIpAddress(), 'userAgent' => UserUtil::getUserAgent(), 'lastActivityTime' => TIME_NOW, 'requestURI' => UserUtil::getRequestURI(), 'requestMethod' => $requestMethod, 'userData' => $serializedUserData, 'sessionVariables' => '', 'userID' => $user->userID, 'isNew' => true));
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:48,代码来源:SessionFactory.class.php


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