Sometimes you can tell the difference between WIFI and non-WIFI, and sometimes you cannot tell any difference.
You cannot distinguish 3G / 4G / LTE from php.
Assumptions and Terminology
I assume that the smartphone connects to your HTTP server through a browser, and your server uses PHP to process the request. If this is not the case, clarify your question.
Terminology: I will use the word "ISP" to refer to companies that provide Internet services, but are not mobile operators.
What information does the server receive?
When your device connects to the PHP server, it tells the server some information about itself, the server can know the IP address of the device, user agent, etc.
Problem
The problem is that the browser doesnβt care what connection it is on, and it does not affect the information that the browser sends to the server. If the browser is included in 3G / 4G / LTE, it will send the same information that it would send if it were on Wi-Fi.
Semi "Proof": The HTTP protocol that transfers data from the device to the HTTP server does not fully know the underlying network stack.
How to determine the connection, then?
The only difference between Wi-Fi / Non-Wi-Fi: IP address.
ISP has a large list of reserved IP addresses. If you find that this IP address belongs to a specific Internet service provider, it must be a Wi-Fi connection.
Similarly, telecom operators have a large list of reserved IP addresses. If you find that this IP address belongs to a specific carrier of the phone, it must be a 3G / 4G / LTE connection!
Doing this in practice
We need to somehow map each IP address to ISP / Carrier, one way to do this is to have a huge database of all providers / carriers and their corresponding reserved IP addresses. In practice, a simple WHOIS search can reveal the source.
For example, a WHOIS search for random IP: 109.168.97.31 showed, among other things:
descr: 013 Netvision
Netvision is an Israeli ISP. Therefore, if it is a telephone connection (you can check it with a user agent), it must be a Wi-Fi connection!
Doing this in PHP
I have little knowledge of PHP, maybe someone with better knowledge will edit this section better. The code will probably look like this:
$company_name = geoip_isp_by_name($_SERVER['REMOTE_ADDR']); $this_is_a_wifi_connection = is_this_wifi($company_name);
The is_this_wifi function should look up the company name in the database and decide whether it is a telephone company or a provider company.
Problems
You still need to have an ISP / Carriers list to compare your WHOIS searches with them.
Some people use a VPN / anonymity network, the IP address may be lying.
Some companies are both providers and carriers, you will never know whether it is a Wi-Fi connection in this case.