Submit Your Article Forum Rules

Results 1 to 4 of 4

Thread: PHP - Get Computer Name

  1. #1
    Senior Member
    Join Date
    Jan 2004
    Posts
    115

    PHP - Get Computer Name

    Hi,

    Does anyone know how I can get the name of a computer using PHP.

    Thanks,

    Darren
    Darren Darkins

  2. #2
    WebProWorld MVP
    Join Date
    Aug 2003
    Posts
    1,039
    If you're after the name of the host the PHP script is running on you can use $_SERVER['SERVER_NAME'];

    If you're after the name of a computer that's connected to the script you can get it's IP from $_SERVER['REMOTE_ADDR'] and gethostbyaddr.

    Code:
    echo gethostbyaddr('127.0.0.1');
    Will return the name of the local host.

    If none of those are what you are after then let me know and I'll try again.

  3. #3
    Senior Member
    Join Date
    Jan 2004
    Posts
    115
    Hi speed,

    thanks for that - I'm probably not making it clear what I need as a lot of people on other forums have offered the same solution.

    I'm looking to get the actual name that the user gives the computer, which might be a windows only thing? For example, I have a laptop I call D-LAPTOP.

    Hope that makes a bit more sense - it's a bit of a long shot anyway as I guess it isn't the sort of information you should be able to just access.

    THanks for your help
    Darren Darkins

  4. #4
    WebProWorld MVP
    Join Date
    Aug 2003
    Posts
    1,039
    Ok, I don't use PHP on Windows nor do I have it installed to test this but have you tried reading the environment variable COMPUTERNAME?

    getenv('HOSTNAME') should return the host name on Linux.

Similar Threads

  1. Getting a new computer
    By cutiger95 in forum The Castle Breakroom (General: Any Topic)
    Replies: 1
    Last Post: 04-12-2007, 10:06 AM
  2. New Computer Store
    By cybersprinter in forum Introductions
    Replies: 2
    Last Post: 02-24-2006, 11:38 AM
  3. Computer Mouse
    By WPW_Feedbot in forum Graphics & Design Discussion Forum
    Replies: 0
    Last Post: 03-27-2005, 01:00 AM
  4. Any one know how to get pop up ads off my computer
    By loseriam in forum WebProWorld: Guidelines/Announcements/Suggestions
    Replies: 3
    Last Post: 09-16-2004, 04:54 AM
  5. Sex Of A Computer
    By matauri in forum The Castle Breakroom (General: Any Topic)
    Replies: 53
    Last Post: 01-23-2004, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •