Page 1 of 2
Can PHP get the computer name ?
Posted: Fri Jan 05, 2007 6:31 am
by christian_phpbeginner
Hello folks,
Does anybody know if PHP could get the computer name and other information about the user's computer ?
I am developing a web-based form and my boss wants me to get all the computer name where the data came from.
Thanks a lot,
Chris
Posted: Fri Jan 05, 2007 6:40 am
by dibyendrah
I think $HTTP_SERVER_VARS
Posted: Fri Jan 05, 2007 6:43 am
by volka
The computer name is (in general) not part of a http request.
Also think about settop boxes or recent consoles. What "name" do they have?
Posted: Fri Jan 05, 2007 7:01 am
by onion2k
This will work. Well, I say work, I mean "will work in a
very limited set of circumstances". The user has to be accessing the script with IE, and it has to be set to a very low security level. And even then it'll prompt them to ask if they want to run it.
Code: Select all
<script>
try
{
var ax = new ActiveXObject("WScript.Network");
document.write('User: ' + ax.UserName + '<br />');
document.write('Computer: ' + ax.ComputerName + '<br />');
}
catch (e)
{
document.write('Permission to access computer name is denied' + '<br />');
}
</script>
Posted: Fri Jan 05, 2007 11:35 am
by aaronhall
Why does your boss want the computer name? If it's to uniquely identify the user, you could either record the IP address or set a cookie, though neither of which are 100% reliable.
Posted: Sat Jan 06, 2007 11:47 pm
by dibyendrah
onion2k wrote:This will work. Well, I say work, I mean "will work in a
very limited set of circumstances". The user has to be accessing the script with IE, and it has to be set to a very low security level. And even then it'll prompt them to ask if they want to run it.
Code: Select all
<script>
try
{
var ax = new ActiveXObject("WScript.Network");
document.write('User: ' + ax.UserName + '<br />');
document.write('Computer: ' + ax.ComputerName + '<br />');
}
catch (e)
{
document.write('Permission to access computer name is denied' + '<br />');
}
</script>
In my linux machine output was :
Code: Select all
Permission to access computer name is denied
ActiveXObject works with Windows only and most of the hosting company use linux.
Posted: Sun Jan 07, 2007 12:06 am
by ambivalent
dibyendrah wrote:ActiveXObject works with Windows only and most of the hosting company use linux.
In this case, it doesn't matter what the host is running since the ActiveXObject is running client side - naturally, it won't work on a client running any flavor of Linux or even Windows with Firefox, et al.
gethostbyaddr() will work, given the IP, but it's really only reliable on Windows clients.
Posted: Sun Jan 07, 2007 12:08 am
by feyd
gethostbyaddr() fetches the DNS level name of the IP (if possible.) It works on far more reliably than just Windows boxes.

Posted: Sun Jan 07, 2007 3:32 am
by onion2k
dibyendrah wrote:In my linux machine output was :
Code: Select all
Permission to access computer name is denied
Not very suprising considering I wrote "The user has to be accessing the script with IE".
Posted: Sun Jan 07, 2007 11:42 am
by aaronhall
dibyendrah wrote:ActiveXObject works with Windows only and most of the hosting company use linux.
It's a client-side script -- the server configuration doesn't matter
Re: Can PHP get the computer name ?
Posted: Sun Jan 07, 2007 11:54 am
by timvw
christian_phpbeginner wrote:Does anybody know if PHP could get the computer name and other information about the user's computer ?
First question: WTF is the name of a computer? My machines don't have a name. And since i'm connecting via 3 proxies all your webserver (and the php script that runs on it) gets to see is the connection information from the proxy that is making the actual request... All i'm trying to say is that you will have to narrow down your requirements.
If we were talking about a windows-only LAN, preferably all authenticated (against AD) workstations you could configure IIS to require windows authentication...
Re: Can PHP get the computer name ?
Posted: Sun Jan 07, 2007 2:43 pm
by volka
timvw wrote:First question: WTF is the name of a computer? My machines don't have a name.
Just out of curiosity: What OS is you computer running?
Posted: Sun Jan 07, 2007 2:50 pm
by Kieran Huggins
He might mean the netbios name - all Windows computers have one. You'll never get this info over the web, it would be a major security breach.
If you're on the same local network (LAN), you could run a batch file through shell_exec() to get the netbios name from the IP address, which $_SERVER will give you.
Posted: Wed Jan 10, 2007 12:30 am
by dibyendrah
aaronhall wrote:dibyendrah wrote:ActiveXObject works with Windows only and most of the hosting company use linux.
It's a client-side script -- the server configuration doesn't matter
What if client is using linux rather than windows ? It will not work either.
Posted: Wed Jan 10, 2007 1:03 am
by aaronhall
Correct, but it has nothing to do with who's hosting the site. It's because IE was never ported to linux.