Forum Moderators: coopster
Where you want it in the html, put this:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
There's not a lot to explain, echo just means send the following to the browser. $_SERVER is an array with a number of different informative items, with REMOTE_ADDR being the array element that contains the visitor's IP address.
and Welcome to WebmasterWorld! :)
<?php
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
echo $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
echo $_SERVER['REMOTE_ADDR'];
}
?>
Those statements just saying that if the forwarded field is there, display it, otherwise display the second one.
I think the proxy ip address is overkill for now...but i will keep it in consideration.
I think it's worth baring in mind that this could also depend on the (configuration of the) server you are installing your script on. I've had $_SERVER['REMOTE_ADDR'] return nothing on a server in a large corporate network. But $_SERVER['HTTP_X_FORWARDED_FOR'] returned the correct information.
That is correct. You would probably need a function like this:
<?php
function get_ip_list() {
$tmp = array();
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],',')) {
$tmp += explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$tmp[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$tmp[] = $_SERVER['REMOTE_ADDR'];
return $tmp;
}
?>
dc
function get_ip_list() {
$tmp = array();
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],',')) {
$tmp += explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$tmp[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$tmp[] = $_SERVER['REMOTE_ADDR'];
return $tmp;
}
echo echo implode(",",get_ip_list());