Is there a way to detect if a user is on a wifi connection with php or javascript?

No, there isn't, there is nothing in the IPv4 nor the HTTP transport that even hints at what kind of connection is used, except for the underlying protocol itself, which is usually IPv4 and HTTP.

No, IPv6 doesn't include this information either.

There are two ways to do this that I know of:

  1. Check the IP against a database. This option gives you much more than carrier information, by the way. It can also give you the location and name of the ISP, the domain that maps to this IP, lat/long, zip code, time zone, etc., etc. Look at for a RESTful API that allows this.

  2. Programmatically: This only works on Android version 2.2+. It is a simple check for navigator.connection. Hope this helps. Here is a test page:

        <script type="text/javascript">
            function checkWIFI() {
                var output = document.getElementById('connectionCheck');
                var html = "Checking...<br/>Connection: ";
                if (navigator.connection) {
                    var type = navigator.connection.type;
                    switch (type) {
                        case navigator.connection.UNKNOWN:
                            html += "Unknown";
                        case navigator.connection.ETHERNET:
                            html += "Ethernet";
                        case navigator.connection.WIFI:
                            html += "Wifi";
                        case navigator.connection.CELL_2G:
                            html += "Cell 2G";
                        case navigator.connection.CELL_3G:
                            html += "Cell 3G";
                            html += "Missing";
                } else {
                    html += "Connection type not supported.";
                output.innerHTML = html;
    <body onload="checkWIFI();">
        <div id="connectionCheck">