3

So i am running this website on the intranet. It has a form and some data is filled out and then submitted. Now i also want to get the username of the user, so the user does not have to enter it. So far i tried $username = gethostbyaddr($_SERVER['REMOTE_ADDR]);. This works like a charm as it gives me the computer name of where the data came from. But different users can log into the machine, which is why this doesnt help.

To make it bit more clear on what has worked so far: ComputerA is running XAMPP server. I can connect to the website using ComputerB and when i submitted the data, my sql server has ComputerB as the username. Tried same with ComputerC and it showed ComputerC as well.

What i am looking for is how C:\Users\(name)\Desktop. I want to know what that name is? Also, if you guys can tell me something better which can be unique, that is fine as well. It doesnt have to be the name.

USER420
  • 337
  • 3
  • 12
  • 1
    FYI: `gethostbyaddr()` is very slow. I would not recommend using it on every request. – Anonymous Aug 11 '15 at 22:44
  • For that you need to use .NET and it will only work on an intranet. It will also only automatically pick up the username if the user is using IE. In Firefox and Chrome they'd be prompted for credentials. – developerwjk Aug 11 '15 at 23:01
  • Do you have/direct me to any examples? – USER420 Aug 11 '15 at 23:23

2 Answers2

6
exec("wmic /node:$_SERVER[REMOTE_ADDR] COMPUTERSYSTEM Get UserName", $user);
echo($user[1]);

(This wouldn't work if your PHP server is hosted on a non-windows machine or your linux host has wmic capabilities extended via other tools)

Aby
  • 3
  • 3
Lucas Cardoso
  • 106
  • 1
  • 8
-2

you can use this

<?php 
$serverName = gethostname();
?>