How to get MAC address of client using PHP?

How to get MAC address of client using PHP?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

The Browser Sandbox and the MAC Address Reality

Retrieving a client's MAC address from PHP on the server side is technically impossible in modern web environments. Browsers isolate network stack information strictly behind a CORS (Cross-Origin Resource Sharing) wall. Even if your PHP backend could somehow access the raw socket layer, the HTTP request headers sent by the browser do not include hardware identifiers like the Media Access Control address. Attempting to parse these values from $_SERVER variables or standard headers will always return null or empty strings because the client simply does not transmit them.

To obtain a MAC address, the logic must shift entirely to the client-side execution layer. This requires leveraging JavaScript within the browser context. However, even this approach is fraught with security restrictions designed to prevent fingerprinting attacks. Modern browsers have actively deprecated APIs that expose low-level hardware details to protect user privacy.

The Legacy navigator.hardwareConcurrency and Deprecated APIs

Historically, developers relied on specific JavaScript properties to extract hardware identifiers. The most common attempt involved accessing navigator.hid, which was part of the now-defunct Hardware Abstraction Layer (HAL) proposal. This API allowed direct reading of network interface cards but was removed from the specification around 2015 due to privacy concerns and inconsistent implementation across vendors.

Another frequent misconception involves using navigator.userAgent or navigator.platform. While these strings contain unique identifiers, they are not MAC addresses. They represent the browser version and OS platform respectively. Relying on them for device identification is unreliable because users can change browsers, and many applications block or normalize these strings to prevent tracking.

Network Information API Limitations

The Network Information API (navigator.connection) offers a glimpse into network characteristics, but it does not provide MAC addresses. It exposes properties like effectiveType (e.g., '4g', 'wifi') and saveData. While this can help differentiate between mobile data and Wi-Fi connections, the underlying hardware address remains inaccessible through this standard interface.

Attempting to access the MAC address via Web Bluetooth or WebUSB APIs is another dead end for web applications. These protocols are designed for interacting with external peripherals like keyboards or sensors, not for reading internal network card registers. Furthermore, these APIs require explicit user permission and a secure context (HTTPS), adding complexity that outweighs the utility of simply identifying a device by its MAC.

Server-Side Detection via DHCP Logs

If the requirement is to map a specific IP address to a MAC address, the solution moves away from PHP application code entirely and into network infrastructure management. The standard mechanism for this is the Dynamic Host Configuration Protocol (DHCP) lease table. Most modern routers, switches, and managed servers maintain a log of IP-to-MAC mappings.

From a PHP perspective, you cannot query this data directly from your application logic unless you have administrative access to a database or API provided by your network equipment vendor. Some enterprise-grade firewalls or load balancers expose internal APIs that might return client device fingerprints, but these are proprietary solutions rather than standard web capabilities.

For instance, if you are managing a corporate environment using specific hardware from a provider like those represented at [https://laravelcompany.com], you might find that their infrastructure includes tools for device management that could theoretically correlate IP addresses with known MAC tables. However, this requires integration with their specific backend services, not generic PHP code running on a public-facing server.

Conclusion: Privacy and Technical Feasibility

The fundamental constraint is that the web platform prioritizes privacy over hardware introspection. Browsers intentionally obscure the network stack to prevent advertisers and trackers from building precise profiles of users based on their local network hardware. Consequently, there is no robust, cross-browser JavaScript method to retrieve a MAC address in a standard web application today.

Developers must accept this limitation or resort to alternative identification methods such as generating UUIDs via crypto.randomUUID() on the client side and storing them in a database upon first visit. This approach respects user privacy while maintaining the ability to identify returning clients without relying on deprecated or non-existent hardware APIs.

Our network