Forum Moderators: coopster
<?php
$ip=$REMOTE_ADDR;
echo $ip;
?>
<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo $ip;
?>
<?php
function getIp() {
$ip = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $ip;
}
$ip = getIp();
echo $ip;
?>
$_SERVER['REMOTE_ADDR']return an IP address for you?
REMOTE_ADDRwas not set (or was empty) - I think this was down to the server configuration and the users accessing it over a closed intranet. In this case I had to fall back to HTTP_X_FORWARDED_FOR (which can contain multiple (comma separated) IP addresses if going through multiple proxies). However, if REMOTE_ADDR is set and is a valid IP address then this should take priority as I believe these other headers could be faked, if you are on the world-wide-web.
<?php
$ip=$REMOTE_ADDR;
echo $ip;
?>
$_SERVER['REMOTE_ADDR'] is what you're after.
Does $_SERVER['REMOTE_ADDR'] return an IP address for you?
this is reliant on register_globals being set on the server
I'm sure there's a way because so many sites are able to figure out my own IP, unless they're using Perl or something else.
<?php
function getIp() {
$ip = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $ip;
}
$ip = getIp();
$ip2 = $HTTP_SERVER_VARS['HTTP_X_CLUSTER_CLIENT_IP'];
echo $ip;
print "</br>";
echo $ip2;
$ip3 = $_SERVER['REMOTE_ADDR'];
$ip4 = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip5 = $_SERVER['HTTP_VIA'];
$ip6 = $_SERVER['HTTP_CLIENT_IP'];
echo $ip3;
print "</br>";
print "IP4 is $ip4";
print "</br>";
print "IP5 is $ip5";
print "</br>";
print "IP6 is $ip6";
print "</br>";
?> 10.255.255.4
10.255.255.4
IP4 is
IP5 is
IP6 is