Check whether the user accesses the PC or mobile phone. This is a feature point that we often encounter when we do Web development. It is also a very simple function point, and there are many solutions, such as using native PHP to analyze UA.
However, if you use the ThinkPHP5 framework on your backend, it is easier to solve this function point, because TP5 source code is already packaged, we can use it directly.
Public function index() {if(request()->isMobile()){var_dump(' mobile '); } else {var_dump('PC access '); }}Copy the code
The above example code uses the method encapsulated by TP5. The source code of this method is in the request file, and the method name is isMobile(). The principle is also to determine the access source by analyzing the UA of users.