Php code to get local computer ip address

Hi all,

I am in the need to get ip address of the local computer in the workgroup.It will be good getting ip address or computer name also.

I use the code getenv(“REMOTE_ADDR”);it gives the ip address of the remote server.But i want to get display the ip address of the local computer(i.e 192.168. . )individually alloted in the workgroup.

Please suggest me the possible solution.

Regards,
Subathra.R :slight_smile:

Not with php. There is a way of getting the forwarded proxy ip, but that is limited by security measures and type of web browser.

What is the purpose for wanting the local ip information? With more information about that, others around here will be able to best advise on how such things are normally and best achieved.

you can contact me,I help you, it_allan@sina.com

I have a page which offer our company employees to post their suggestions about us. But somebody posting unnecessary things in the suggestion box, so if i get their ip’s means i can able to warn them personally.That’s the reason i want to get their ip address. Employees suggestion page will open only in my 4 ips used by our office.

So now i am in the need of getting local ip address or computer name .

Regards,
Subathra.R :slight_smile:

I don’t know if you will be able to get their ip address in the way you want.

However, you can investigate the local server logs and compare that with the times that the suggestions were made.

It is also possible to use javascript to send the local ip address, either primitively by attaching it as a querystring onto a blank image request, or via ajax to a server script for storage in the databsae.

Please can you able to provide that script for my further proceedings.

Regards,
Subathra.R

Whoops, java, which can be called via javascript.


if (java && java.net)
ip = ''+java.net.InetAddress.getLocalHost().getHostAddress();
else ip = 'unknown';

If you decide to go with this solution I suggest moving this discussion to the javascript forum.

The following code displays the computer name when it is executed locally.But once it uploaded in server it didnt give the output of computer name just blank space is coming as output in online.

Code : getenv(‘COMPUTERNAME’);

Please clarify me why it is happening like that.

Regards,
Subathra.R

if your server of your system is in your workgroup,you can use this the function “$_SERVER[“REMOTE_ADDR”];” to get your local ip, but if your server is in remote,you can only use any other ways.

in this time ,you can use javascript,not the php code,because php run in server,javascript run in IE,you can use fllow two activex
  <OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></OBJECT>
  <OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>
I had typed the code to solve your issue, please check.
this code can get mac-address,ip-address and sdnsname

It sounds like this will be on an intranet server, rather than over the internet. if this is the case, even if it’s on a Win32 system, you should be able to use the following code:


$IP = $_SERVER['REMOTE_ADDR'];        // Obtains the IP address
$computerName = gethostbyaddr($IP);   // Obtains the "remote host", which, on an intranet is the computer's name

I’ve used this with good success on my local development server, running apache on Windows XP, And I’m reasonably certain that it will work on other platforms, as well.