KraLord
asked on
IP and User's Host
Hello there,
Why i am getting this in just one line?
I want it in 3 different lines
----code-----
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
$host = preg_replace("/^[^.]+./", "*.", $fullhost);
echo $ip;
echo $fullhost;
echo $host;
?>
----end-----
Why i am getting this in just one line?
I want it in 3 different lines
----code-----
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
$host = preg_replace("/^[^.]+./", "*.", $fullhost);
echo $ip;
echo $fullhost;
echo $host;
?>
----end-----
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yep that's the same thing pretty much, without the formatting for the source code and swapping <br> for the xml compliant line breaks i put in
cheers,
loz
cheers,
loz
actually that won't work fine ... it depends on your users ... there are users in private networks etc ... in those cases you'll come up with the proxy in that soluction.
As you should be aware lots of users have a private IP and they contact the proxy and the request comes with the proxy's IP ... therefore two or more users in the same private network come out as the same user in that soluction above ...
You should use this that takes in account the proxy problem:
<?
if ($_SERVER["HTTP_X_FORWARDE D_FOR"] != ""){
$ip = $_SERVER["HTTP_X_FORWARDED _FOR"];
$proxy = $_SERVER["REMOTE_ADDR"];
$fullhost = @gethostbyaddr($_SERVER["H TTP_X_FORW ARDED_FOR" ]);
}else{
$ip = $_SERVER["REMOTE_ADDR"];
$fullhost = @gethostbyaddr($_SERVER["R EMOTE_ADDR "]);
}
$host = preg_replace("/^[^.]+./", "*.", $fullhost);
echo $ip . "<br />\n";
echo $fullhost . "<br />\n";
echo $host . "<br />\n";
?>
just my two cents! :)
Hope it helps...
As you should be aware lots of users have a private IP and they contact the proxy and the request comes with the proxy's IP ... therefore two or more users in the same private network come out as the same user in that soluction above ...
You should use this that takes in account the proxy problem:
<?
if ($_SERVER["HTTP_X_FORWARDE
$ip = $_SERVER["HTTP_X_FORWARDED
$proxy = $_SERVER["REMOTE_ADDR"];
$fullhost = @gethostbyaddr($_SERVER["H
}else{
$ip = $_SERVER["REMOTE_ADDR"];
$fullhost = @gethostbyaddr($_SERVER["R
}
$host = preg_replace("/^[^.]+./", "*.", $fullhost);
echo $ip . "<br />\n";
echo $fullhost . "<br />\n";
echo $host . "<br />\n";
?>
just my two cents! :)
Hope it helps...
you do understand that your code ain't gonna work well with all the users that go to you site right? or are you ok with that?
ASKER
yes Drift3r thanks a lot!
ASKER
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
$host = preg_replace("/^[^.]+./", "*.", $fullhost);
echo $ip . "<br>";
echo $fullhost . "<br>";
echo $host . "<br>";
?>
=)