How to get hostname in a php page?

Hi,
I am building my website in php. I need to track the visitor's record for security. For that, i want visitor's host name. I used below methods, but didnt work any :(

<?PHP
######################################################################################
### SOLUTION 1 ######################################################################
echo "<BR>Solution 1
";
function seeyou()
{
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"),
"unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") &&
strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"),
"unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR']
&& strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return gethostbyaddr($ip);
}
echo "Your Computer : ".seeyou();
?>

<?PHP
######################################################################################
### SOLUTION 2 ######################################################################
echo "<BR>
Solution 2
";
print "Your Computer : ".gethostbyaddr($HTTP_SERVER_VARS['REMOTE_PORT']);
?>

<?PHP
######################################################################################
### SOLUTION 3 ######################################################################
echo "<BR>
Solution 3
";
print "Your Computer [getenv] : ".getenv('COMPUTERNAME');
print "
Your Computer [server] : ".$_SERVER["COMPUTERNAME"];
echo "
Your Computer [Remort Addr] : ".getenv(REMOTE_ADDR);
?>

<?PHP
######################################################################################
### SOLUTION 4 ######################################################################
echo "<BR>
Solution 4
";
print "Your Computer [http_x_forward_for] : ".gethostbyaddr(getenv('HTTP_X_FORWARD_FOR'));
?>

<?PHP
######################################################################################
### SOLUTION 5 ######################################################################
echo "<BR>
Solution 5
";
//echo "
apache_get_version :".apache_get_version();
//echo "
APACHE REMORT ADDER : ". apache_getenv("REMOTE_ADDR");
//echo "
APACHE SERVER ADDER : ".apache_getenv("SERVER_ADDR");
?>
<?PHP
######################################################################################
### SOLUTION 6 ######################################################################
echo "<BR>
Solution 6
";
### DESCRIPTION :: Fetch all HTTP request headers
### Prior to PHP 4.3.0, apache_request_headers() was called getallheaders().
#### PHP 4.3.0, getallheaders() is an alias for apache_request_headers().

//$headers = getallheaders();
//$headers = apache_request_headers();
//foreach ($headers as $header => $value) {
// echo "$header: $value

";
//}
?>

Also, i found that we need to set 'HostnameLookups' in apache to 'on'. I did it also. But end up with no result.

Can anyone help me?
Thanks in advance.

Comments

  • try this

    [code]

    <?
    $ip = getenv("REMOTE_ADDR"); ?> //get users ip address

    <?php echo($ip) ?> // show users ip address

    [/code]

    hope it helps
    Slewis
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion