Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
7b682ae9
Commit
7b682ae9
authored
Jul 29, 2007
by
Dries Buytaert
Browse files
- Patch
#162944
by profix898: cleanup ip_address() code.
parent
80ff5109
Changes
1
Hide whitespace changes
Inline
Side-by-side
includes/bootstrap.inc
View file @
7b682ae9
...
...
@@ -1077,7 +1077,6 @@ function language_default($property = NULL) {
return
$property
?
$language
->
$property
:
$language
;
}
/**
* If Drupal is behind a reverse proxy, we use the X-Forwarded-For header
* instead of $_SERVER['REMOTE_ADDR'], which would be the IP address
...
...
@@ -1087,20 +1086,15 @@ function language_default($property = NULL) {
* IP address of client machine, adjusted for reverse proxy.
*/
function
ip_address
()
{
static
$
remote_ip
;
static
$
ip_address
=
NULL
;
if
(
$remote_ip
)
{
// We have been here before, so just return the one we processed before
return
$remote_ip
;
}
else
{
$remote_ip
=
$_SERVER
[
'REMOTE_ADDR'
];
if
(
variable_get
(
'reverse_proxy'
,
FALSE
)
&&
array_key_exists
(
'HTTP_X_FORWARDED_FOR'
,
$_SERVER
))
{
$ip_array
=
explode
(
','
,
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
]);
if
(
!
isset
(
$ip_address
))
{
$ip_address
=
$_SERVER
[
'REMOTE_ADDR'
];
if
(
variable_get
(
'reverse_proxy'
,
0
)
&&
array_key_exists
(
'HTTP_X_FORWARDED_FOR'
,
$_SERVER
))
{
// If there are several arguments, the leftmost one is the farthest client
$remote_ip
=
$ip_array
[
0
]
;
list
(
$ip_address
,
)
=
explode
(
','
,
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
])
;
}
}
return
$
remote_ip
;
return
$
ip_address
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment