获取手机扫码后的浏览器类型,可以读取是安卓系统还是IOS系统。

文章目录[隐藏]

本站右侧有一个APP扫码,细心的小伙伴就会发现,当你使用IOS或者安卓扫码的时候会跳转出不同的页面,这个功能到底是怎样实现的呢?其实很简单,就是利用浏览器UA来进行判断的,接下来我就提供一段PHP代码来教大家实现这个功能。

PHP代码

<?php
	if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')){
		echo '<div class="mui-input-row" style="text-align:center;margin:5px;display:block">
			<button id="按钮2" type="button" class="mui-btn mui-btn-primary" style="width:100%;height:40px;float:none;margin:0px 0px 0px 0px;font-size:14px;">IOS系统下载(暂未提供)</button>
		</div>';
	} else
	if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
		echo '<div class="mui-input-row" style="text-align:center;margin:5px;display:block">
			<button id="按钮2" type="button" class="mui-btn mui-btn-primary" style="width:100%;height:40px;float:none;margin:0px 0px 0px 0px;font-size:14px;">IOS系统下载(暂未提供)</button>
		</div>';
	} else
	if (strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
		echo '<div class="mui-input-row" style="text-align:center;margin:5px;display:block">
			<button id="按钮1" type="button" class="mui-btn mui-btn-primary" style="width:100%;height:40px;float:none;margin:0px 0px 0px 0px;font-size:14px;" onclick=window.location.href="com.svlik.www.apk">Android系统下载</button></div>';
	} else {
		echo '<div class="mui-input-row" style="text-align:center;margin:5px;display:block">
			<button id="按钮2" type="button" class="mui-btn mui-btn-primary" style="width:100%;height:40px;float:none;margin:0px 0px 0px 0px;font-size:14px;">IOS系统下载(暂未提供)</button>
		</div>
		<div class="mui-input-row" style="text-align:center;margin:5px;display:block">
			<button id="按钮1" type="button" class="mui-btn mui-btn-primary" style="width:100%;height:40px;float:none;margin:0px 0px 0px 0px;font-size:14px;" onclick=window.location.href="com.svlik.www.apk">Android系统下载</button>
		</div>';
	}

?>

使用方法

大家只需要将以上代码存为PHP即可。然后将链接生成为二维码,提供给手机扫码即可实现该功能。

声明:本文为原创,作者为 Svlik,转载时请保留本声明及附带文章链接:http://www.svlik.com/1200.html