How to grab 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

Post Reply
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

How to grab computer name

Post by sheepz »

Was wondering how would I got about grabbing the clients computer name and displaying on the same page. This is for a intranet site for work, thanks. :?:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Maybe try gethostbyaddr() if this is intranet it may work ;)
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

The code "gethostbyaddr()" will not work over the internet? There is no code that will be able to grab the host computer name as they visit the site? Regardless if its intranet or internet? THanks for the reply! =)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

That function should work for both...

EDIT | Overt internet you will just get the address the ISP assign if it's not a server. Something like:
cpc3-midd5-6-0-cust205.midd.cable.ntl.com
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

thx going to test it out =)
FTJoe
Forum Newbie
Posts: 10
Joined: Sun Jul 17, 2005 8:00 pm

Re: How to grab computer name

Post by FTJoe »

I'm not too sure what the code is, but make it so it traces their C drive and goes to the following route: C:\Documents and Settings
Then make it so it chooses a username other than Administrator, Default User, All Users or Guest.

Or if it's possible make it check the start bar's explorer and make it trace which folder was automaticaly opened..because it always opens the current user's account..
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

gethostbyaddr

Post by sheepz »

I used the example:

<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

echo $hostname;
?>

I get a "localhost" as a response. Hrm... must be missing something because that is not my computer name. Am I using the "gethostbyaddr" command correctly?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

That "IS" your computer name if you're running the script or your own machine.

Your local machine is a special case. Local loopback equates to 127.0.0.1 which is "localhost" ;)
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

I call my computer: "Joseph" (after a Soviet politician of the first half of the 20th century.) That would be a bit hard to check, wouldn't it?
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

ahhh didn't know if I was using the command correctly. :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: How to grab computer name

Post by Chris Corbyn »

FTJoe wrote:I'm not too sure what the code is, but make it so it traces their C drive and goes to the following route: C:\Documents and Settings
Then make it so it chooses a username other than Administrator, Default User, All Users or Guest.

Or if it's possible make it check the start bar's explorer and make it trace which folder was automaticaly opened..because it always opens the current user's account..
PHP will never access somebody's PC and invade their privacy in such a way as this. If somebody could get into my documents and settings remotely I'd be a bit worried. Besides... I use Linux :P
Post Reply