Can PHP get the computer name ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Can PHP get the computer name ?

Post 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
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

I think $HTTP_SERVER_VARS
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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>
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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.
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

gethostbyaddr() fetches the DNS level name of the IP (if possible.) It works on far more reliably than just Windows boxes. ;)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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".
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Can PHP get the computer name ?

Post 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...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Can PHP get the computer name ?

Post 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?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Correct, but it has nothing to do with who's hosting the site. It's because IE was never ported to linux.
Post Reply