Merge pull request #22 from kafene/master

a few changes to request.php
pull/25/head
Mike Cao 12 years ago
commit 2709c2502f

@ -46,7 +46,7 @@ class Request {
'base' => str_replace('\\', '/', dirname(getenv('SCRIPT_NAME'))),
'method' => getenv('REQUEST_METHOD') ?: 'GET',
'referrer' => getenv('HTTP_REFERER') ?: '',
'ip' => $this->getIpAddress(),
'ip' => getenv('REMOTE_ADDR'),
'ajax' => getenv('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest',
'scheme' => getenv('SERVER_PROTOCOL') ?: 'HTTP/1.1',
'user_agent' => getenv('HTTP_USER_AGENT') ?: '',
@ -56,7 +56,10 @@ class Request {
'query' => new Collection($_GET),
'data' => new Collection($_POST),
'cookies' => new Collection($_COOKIE),
'files' => new Collection($_FILES)
'files' => new Collection($_FILES),
'secure' => getenv('HTTPS') && getenv('HTTPS') != 'off',
'accept' => getenv('HTTP_ACCEPT'),
'proxy' => $this->getProxyIpAddress()
);
}
@ -109,28 +112,25 @@ class Request {
*
* @return string IP address
*/
private function getIpAddress() {
static $vars = array(
private function getProxyIpAddress() {
static $forwarded = array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
'HTTP_FORWARDED'
);
$flags = \FILTER_FLAG_NO_PRIV_RANGE | \FILTER_FLAG_NO_RES_RANGE;
foreach ($vars as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
foreach ($forwarded as $key) {
if (array_key_exists($key, $_SERVER)) {
sscanf($_SERVER[$key], '%[^,]', $ip);
if(filter_var($ip, FILTER_VALIDATE_IP, $flags) !== false) {
return $ip;
}
}
}
}
return '';
}
}
?>

Loading…
Cancel
Save