-4
ipAddress=$_SERVER['REMOTE_ADDR'];
$macAddr=false;

#run the external command, break output into lines
$arp=`arp -a $ipAddress`;
$lines=explode("\n", $arp);

#look for the output line describing our IP address
foreach($lines as $line)
{
   $cols=preg_split('/\s+/', trim($line));
   if ($cols[0]==$ipAddress)
   {
       $macAddr=$cols[1];
   }
}
echo $macAddr;

It's not working in server.

S.L. Barth
  • 5,486
  • 8
  • 38
  • 47
akhil
  • 1
  • 1
  • 1
  • 1
    the result of 'not working' is not enough for anyone to help: what's not working? – schroeder May 18 '17 at 06:36
  • 3
    Are you aware of how ARP works? The fact that you are asking about both PHP *and* JS makes it appear that you are unaware that MAC addresses do not get passed to servers on the Internet – schroeder May 18 '17 at 06:37
  • 1
    PHP get executed on server, you will only be able to get server's mac address, not client. And javascript can't access system things so you won't get mac address, and by the way, what would you do with a client's mac address ? Unless you can be "phyisically" (LAN/VLAN) on the same network it's uterly useless. – Walfrat May 18 '17 at 07:21
  • I dont have the rep to mark it myself. But I consider this a duplicate of [this question](http://stackoverflow.com/questions/1420381/how-can-i-get-the-mac-and-the-ip-address-of-a-connected-client-in-php) – Snappie May 18 '17 at 10:35

1 Answers1

3

You don't understand what you are doing. All PHP code (and also the backtick/exec/system commands) is executed on the server.

There is no portable/reliable way to get the MAC address. Maybe a browser plugin could do that.

Consider that the client can also not have any MAC addresses at all. For example when connecting via PPP.

filo
  • 303
  • 1
  • 5