Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hallo..
I have a question. How can I get the computer name that now I use using PHP Code?
I always find php code that get IP addres and server name only, not for local computer name..
help me please..
thank you..
Posted
Updated 8-May-23 20:45pm

JavaScript
function GetComputerName()
{
    try
    {
        var network = new ActiveXObject('WScript.Network');
        // Show a pop up if it works
        alert(network.computerName);
    }
    catch (e) { }
}


This is javascript that will work in IE, sometimes. That's the best you can do. You can then push that value in to a control and then when the user posts to the server, you can read it in PHP. PHP can't do what you want because it runs on the server, not the client, so it can't look up client data.
 
Share this answer
 
Comments
NurSalsabila 14-Jun-13 0:54am    
I think you're right that PHP can't do it, because it runs on server.
i had try that code.. but I got an error because the Var. it can't read in PHP.
there is no other way?
Christian Graus 14-Jun-13 0:55am    
This is javascript. It runs on the client. On IE. Sometimes. No, there's no other way.
Hi NurSalsabila , this is how I get the computer name

PHP
<?php
//get host by name
echo gethostname();
echo "<br>";
//get OS
echo php_uname();
?>


:)
 
Share this answer
 
Comments
Christian Graus 14-Jun-13 0:55am    
The server name.....
NurSalsabila 14-Jun-13 0:57am    
i had try this code but that code get the server name only, not for client computer..
<pre><?php
	echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
	?>


This will show the PC name or the IP on some mobile devices.
 
Share this answer
 
Comments
OriginalGriff 30-May-19 2:53am    
This question is 6 years old, and you have added nothing to it. This will never return a PC name, and the IP address it supplies is that of the router, not the PC.

While I applaud your urge to help people, it's a good idea to stick to new questions, rather than 6 year old ones. After that amount of time, it's unlikely that the original poster is at all interested in the problem any more!
Answering old questions - particularly with poor answers - can be seen as rep-point hunting, which is a form of site abuse. The more trigger happy amongst us will start the process of banning you from the site if you aren't careful. Stick to new questions and you'll be fine.
Member 14475217 30-May-19 3:04am    
sorry about that. i really did not notice the date.
i have this running in with my html and tested on 7 pc's and mobile devices.
but i also have to add that this is just on my local network.

i will be more careful with answering old Questions
OriginalGriff 30-May-19 3:14am    
:thumbsup:
Member 14475217 30-May-19 8:18am    
if you use it like you will get the IP add of the device

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900