PHP 判断客户端是手机端还是电脑的;一般的这种判断都是加在JavaScript里面的;
有时间接口里面需要这个但是接口没有给你传,这个就需要PHP自己去判断了
个人感觉PHP判断比js要简单的多,PHP强大的$_SERVER函数;
<?php //在header里面拿到客户端的信息Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 $agent = strtolower($_SERVER['HTTP_USER_AGENT']); //然后根据strpos函数查找你要判断的客户端类型 //例如我要判断 Windows或ipad if(strpos($agent, 'windows')>0||strpos($agent, 'pad')>0) { //............ } /** *$_SERVER信息如下 **/ Array ( [HTTP_HOST] => localhost [HTTP_CONNECTION] => keep-alive [HTTP_CACHE_CONTROL] => max-age=0 [HTTP_UPGRADE_INSECURE_REQUESTS] => 1 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 [HTTP_ACCEPT_ENCODING] => gzip, deflate, br [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_COOKIE] => a0537_times=3; UM_distinctid=15d02e2e01f6-0f4ab884e85d8a-474b0421-100200-15d02e2e020fe; CNZZDATA1260520261=1135890009-1498991043-%7C1498991043; Hm_lvt_58347d769d009bcf6074e9a0ab7ba05e=1498282664,1499393186,1499415898,1499837253; remember_admin_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6ImVsU2hTcjJMRG80R2J0XC9rNnRubjB3PT0iLCJ2YWx1ZSI6Ikx4RE81a0t5YXdUNmFCZkpOWDNaRm5VemQrV2lTRjZyNzdCZnR3WUpOaCs4ejlGRHFBQmFiemlkK0FNbENlYTJuV2YxME1pTW5Gb2pPemppaUpPVzIzS2wwV2xsXC80Q0E5RkVjNEl3Q1RQND0iLCJtYWMiOiIwZGRjZTgzMGMwMzQyMjVmZTQ4NDFmYjA5NzE4YTk1ODNmOTA1MjJkZGMyOTgxNGQ5MjUyMmFlZjc4MzlhOTJmIn0%3D; userName=admin; userPass=admin [PATH] => C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;I:\bin;H:\php\php-7.0.12-nts;C:\ProgramData\ComposerSetup\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;H:\MySQL\bin;C:\ProgramData\ComposerSetup\bin;C:\Program Files\PuTTY\; [SystemRoot] => C:\Windows [COMSPEC] => C:\Windows\system32\cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC [WINDIR] => C:\Windows [SERVER_SIGNATURE] => <address>Apache/2.4.18 (Win64) PHP/7.0.4 Server at localhost Port 80</address> [SERVER_SOFTWARE] => Apache/2.4.18 (Win64) PHP/7.0.4 [SERVER_NAME] => localhost [SERVER_ADDR] => ::1 [SERVER_PORT] => 80 [REMOTE_ADDR] => ::1 [DOCUMENT_ROOT] => G:/wamp64/www [REQUEST_SCHEME] => http [CONTEXT_PREFIX] => [CONTEXT_DOCUMENT_ROOT] => G:/wamp64/www [SERVER_ADMIN] => admin@example.com [SCRIPT_FILENAME] => G:/wamp64/www/test/1.php [REMOTE_PORT] => 50317 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /test/1.php [SCRIPT_NAME] => /test/1.php [PHP_SELF] => /test/1.php [REQUEST_TIME_FLOAT] => 1505178506.424 [REQUEST_TIME] => 1505178506 ) ?>