本文整理汇总了PHP中Header::buildEntityArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Header::buildEntityArray方法的具体用法?PHP Header::buildEntityArray怎么用?PHP Header::buildEntityArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Header
的用法示例。
在下文中一共展示了Header::buildEntityArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBuildEntityArrayWithValueOnly
public function testBuildEntityArrayWithValueOnly()
{
$headerStr = '10.0.0.1,10.0.0.2,10.0.0.3';
$header = new \Header('X-Forwarded-For', $headerStr, ',');
$header->parseParams();
$this->assertEquals(3, $header->count());
$partsArray = $header->toArray();
$this->assertEquals('10.0.0.1', $partsArray[0]);
$entityArray = $header->buildEntityArray();
$this->assertEquals(3, count($entityArray[0]));
}
示例2: setClientInfo
/**
* Sets the IP address and User Agent of the requesting client. It checks for the presence of
* a Forwarded or X-Forwarded-For header and, if present, it uses the left most address listed.
* If both of these headers is present, the Forwarded header takes precedence.
* If the header is not present, it defaults to the REMOTE_ADDR value
*/
public function setClientInfo()
{
$ipAddress = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
if (array_key_exists('HTTP_FORWARDED', $_SERVER)) {
$header = new Header('Forwarded', $_SERVER['HTTP_FORWARDED'], ';');
$header->parseParams();
$header->setGlue(',');
$header->parseParams();
$elementArray = $header->buildEntityArray();
$elementArray = array_change_key_case($elementArray);
if (isset($elementArray['for']) && count($elementArray['for'])) {
$ipAddress = $elementArray['for'][0];
}
if (isset($elementArray['user-agent']) && count($elementArray['user-agent'])) {
$userAgent = $elementArray['user-agent'][0];
}
} elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
$header = new Header('X-Forwarded-For', $_SERVER['HTTP_X_FORWARDED_FOR'], ',');
$header->parseParams();
$elementArray = $header->buildEntityArray();
$ipAddress = count($elementArray) ? $elementArray[0] : null;
}
$this->clientIP = $ipAddress;
$this->clientUserAgent = $userAgent;
}