I have this website. and on one page I setup this php script that shows the IP address of the visitor along with the browser that the visitor is using.
Now there is another thing that I want to show to the visitor and that is the hostname if their ISP.
Say the IP address of a visitor is: 123.456.78.90
and their hostname is something like: Washington-HSE.bell.com
I want to display that information to the visitor, so it would show on the page.
I’m not a php guru, but so far I managed to use any script that I found on the internet. However I wasn’t able to find one that shows the hostname, all of them are about the IP address.
I wonder if you guys can help me with it, I also looked up on the forums but didn’t find the answer to my question…
However, here is the piece of php code that I’m using:
<?php
$hst = $_SERVER[“HTTP_HOST”]; // This shows the domain name where the website is.
$uri = $_SERVER[“REQUEST_URI”]; // This line shows the name of the requested page.
$rmt = $_SERVER[“REMOTE_ADDR”]; // This shows visitor’s IP address.
$br = $_SERVER[“HTTP_USER_AGENT”]; // This shows the browser version the visitor is using.
echo “<font color=‘#A00000’>Your IP address is:</font><br/><font color=‘#FF0000’> $rmt
<br/>
<font color=‘#A00000’>The browser you are using is:</font><br/> $br<br/>”;
?>
<?php
// For Linux...
function gethost ($ip) {
$host = `host $ip`;
return (($host ? end ( explode (' ', $host)) : $ip));
}
// For Win32...
function nslookup ($ip) {
$host = split('Name:',`nslookup $ip`);
return ( trim (isset($host[1]) ? str_replace ("\
".'Address: '.$ip, '', $host[1]) : $ip));
}
?>
it will do what you want BUT remember its executing command as shell/command prompt on *NIX/Windows. so you should have SAFE MODE off (i think)
ok here’s where i found it. http://ca.php.net/gethostbyaddr
it gets the output from these command then you can use regular expression to get what you want
Wow guys!
I’m impressed by the speed that you reply to my thread… almost can’t keep up.
Hi Computerages… same thing, that returns the IP
Hello Jas! for some reason your solution doesn’t work for me. I’m using WinXP for the server, and I tried the Win version of your code. It doesn’t return anything, not even an error.
Hi Drzoid!
ok my setup… i have couple of computers on the network.
One of them is the webserver, another is this computer that I’m using, and I’m trying to access my website from the internet, using the domain name and not the internal ip address of the webserver, that is on the network.
Jas!
I think I’m not quite getting what you’re trying to tell me… my bad.
I don’t know what you mean by “check your safe mode is off”
About writting my own function… consider me a noob, that might be something simple, but I guess I don’t know how to do it.
The computer that I am using now to reply to you guys, is just one on the network.
The webserver computer is in another room, and I never use that for anything else, it is exclusively used as a webserver.
then if you want you can turn off the safe mode (NOT A GOOD IDEA THOUGH IF YOU DONT TAKE PROPER CARE).
you can turn it off in php.ini (if in your control)