What is a MAC address?
MAC is the abbreviation of “Media Access Control” and it is a 48-bit physical address associated with every networking device. It is printed on the NIC(Network Interface Card) and is globally unique for every networking device. MAC address is used by the data-link layer to route a data packet from source to destination.
What is an IP address?
An Internet Protocol(IP) address also known as a logical address is given by the internet service provider(ISP) which uniquely identifies a system over the network. IP address keeps on changing time to time.
How to get the IP address of the connected client in PHP: $_SERVER is a PHP superglobal variable which holds information about the header, path and script locations. Superglobal variables are the predefined variables which are always accessible. These superglobals store information in the form of associative-array, and here we are going to fetch the ‘REMOTE_ADDR’ key of the $_SERVER associative array to get the client’s IP Address. ‘REMOTE_ADDR’ returns the client’s IP address
Example 1: This example illustrates how to get Client’s IP Address using $_SERVER[‘REMOTE_ADDR’].
Client's IP address is: ::1
Note: For an online IDE, it may show runtime error or it will not show any output because private domains don’t share their IP. For localhost, IP address is 127.0.0.1 that is a loopback address and so the client’s IP address is ::1.
How to get the MAC address of the connected client in PHP: The ‘exec()’ is a function which is used to run an external program in PHP. It returns the last line from the result of the command. To get the MAC address, pass the parameter ‘getmac’ which returns the MAC address of the client. ‘getmac’ is a CMD command to get the MAC address.
Example 2: This example get the MAC Address using exec() function.
MAC address of client is: 00-20-10-2A-03-0A
Note: This code will not work on online IDE, because ‘getmac’ is a CMD command. Try running it on localhost.
- PHP | Determining Client IP Address
- MAC Full Form
- How to Get Local IP Address of System using PHP ?
- Server side and Client side Programming
- Client-Server Model
- How to set alternate content for users that do not support client-side scripts ?
- HTTP status codes | Client Error Responses
- How to create a client-side image-map in HTML5 ?
- How to identify server IP address in PHP ?
- Address Calculation Sort using Hashing
- HTML | address Tag
- HTML | DOM Address Object
- Perl | Extract IP Address from a String using Regex
- How to instantiate Struct Pointer Address Operator in Golang?
- How to check if email address is already in use or not using express-validator in Node.js ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.