本文整理匯總了PHP中Header::setGlue方法的典型用法代碼示例。如果您正苦於以下問題:PHP Header::setGlue方法的具體用法?PHP Header::setGlue怎麽用?PHP Header::setGlue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Header
的用法示例。
在下文中一共展示了Header::setGlue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testBuildEntityArray
public function testBuildEntityArray()
{
$headerStr = 'For=10.0.0.1;user-agent="test;test;test;test";For=10.0.0.2;user-agent="secondLevel;
some date";for=10.0.0.3;user-agent="thirdLevel"';
$header = new \Header('Forwarded', $headerStr, ';');
$header->parseParams();
$header->setGlue(',');
$header->parseParams();
$entityArray = $header->buildEntityArray();
$this->assertEquals(3, count($entityArray['For']));
$this->assertEquals(3, count($entityArray['User-agent']));
}
示例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;
}