本文整理汇总了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();
}