判断用户是PC还是移动端的php代码
本文我们来分享用php如何识别用户是通过 PC、iPad 还是手机,然后我们还可以看看腾讯的通过JS语句判断WEB网站的访问端是电脑还是手机。
先我们来看看一段用php如何识别用户是通过 PC、iPad 还是手机来访问网站?
$uAgent = $_SERVER['HTTP_USER_AGENT'];
$osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|XWindow|ubuntu|Longhorn|AIX|Linux|AmigaOS|BEOS|HP-UX|OpenBSD|FreeBSD|NetBSD|OS\/2|OSF1|SUN";
if(preg_match("/($osPat)/i", $uAgent ))
{
echo "来着PC访问";
}
else
{
echo "其他终端访问";
}
?>
以下是腾讯的通过JS语句判断WEB网站的访问端是电脑还是手机
腾讯网的适配代码
如何判断访问网站的机器类型-如何判断ipad
JS 判断浏览器客户端类型(ipad,iphone,android)
腾讯网的适配代码
如何判断访问网站的机器类型-如何判断ipad
如何判断是否是 iPad 浏览器呢,关键是看它的 User Agent 中是否有 iPad。iPad 使用的是 Safari Mobile 浏览器,他的的 User Agent 是:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
function is_iPad(){
[object Object] [object Object] [object Object]var ua = navigator.userAgent.toLowerCase();
[object Object] [object Object] [object Object]if(ua.match(/iPad/i)=="ipad") {
[object Object] [object Object] [object Object] [object Object] [object Object] [object Object]return true;
[object Object] [object Object] [object Object]} else {
[object Object] [object Object] [object Object] [object Object] [object Object] [object Object]return false;
[object Object] [object Object] [object Object]}
}
$is_iPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.fairyfish.net [R=301]
JS 判断浏览器客户端类型(ipad,iphone,android)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to set the screen rotation lock on iPad 'Know it in seconds: How to set the screen not to rotate on iPad'

How to use Follow Up in the Mail app on iPhone, iPad, and Mac

Share 8 common reasons and solutions: Reasons and solutions for iPad unable to connect to WiFi!

How to split screen on iPad How to split screen on two apps on iPad

How long is the lifespan of Apple iPad? Quickly understand

Why does my iPad not show that it is charging?
