本文整理匯總了PHP中WebRequest::getIP方法的典型用法代碼示例。如果您正苦於以下問題:PHP WebRequest::getIP方法的具體用法?PHP WebRequest::getIP怎麽用?PHP WebRequest::getIP使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WebRequest
的用法示例。
在下文中一共展示了WebRequest::getIP方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetIpLackOfRemoteAddrThrowAnException
/**
* @expectedException MWException
* @covers WebRequest::getIP
*/
public function testGetIpLackOfRemoteAddrThrowAnException()
{
// ensure that local install state doesn't interfere with test
$this->setMwGlobals(array('wgSquidServersNoPurge' => array(), 'wgSquidServers' => array(), 'wgUsePrivateIPs' => false, 'wgHooks' => array()));
$request = new WebRequest();
# Next call throw an exception about lacking an IP
$request->getIP();
}
示例2: incrMissesRecent
/**
* Roughly increments the cache misses in the last hour by unique visitors
* @param WebRequest $request
* @return void
*/
public function incrMissesRecent(WebRequest $request)
{
if (mt_rand(0, self::MISS_FACTOR - 1) == 0) {
$cache = ObjectCache::getLocalClusterInstance();
# Get a large IP range that should include the user even if that
# person's IP address changes
$ip = $request->getIP();
if (!IP::isValid($ip)) {
return;
}
$ip = IP::isIPv6($ip) ? IP::sanitizeRange("{$ip}/32") : IP::sanitizeRange("{$ip}/16");
# Bail out if a request already came from this range...
$key = wfMemcKey(get_class($this), 'attempt', $this->mType, $this->mKey, $ip);
if ($cache->get($key)) {
return;
// possibly the same user
}
$cache->set($key, 1, self::MISS_TTL_SEC);
# Increment the number of cache misses...
$key = $this->cacheMissKey();
if ($cache->get($key) === false) {
$cache->set($key, 1, self::MISS_TTL_SEC);
} else {
$cache->incr($key);
}
}
}
示例3: check
/**
* Test against the passed WebRequest
* @param WebRequest $request
* @return Status
*/
public function check(WebRequest $request)
{
$ok = ['ip' => $this->checkIP($request->getIP())];
$status = Status::newGood();
$status->setResult($ok === array_filter($ok), $ok);
return $status;
}
示例4: WebRequest
/**
* @expectedException MWException
*/
function testGetIpLackOfRemoteAddrThrowAnException()
{
$request = new WebRequest();
# Next call throw an exception about lacking an IP
$request->getIP();
}