JS屏蔽电脑端代码,屏蔽win电脑端与苹果笔记本Mac(屏蔽后会跳转指定网址),感觉这个比PHP屏蔽好用一点(因为一般别人在F12控制台伪造了UA 也会被屏蔽)
<script type="text/javascript">
var system ={
win : false,
mac : false,
xll : false
};
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){
window.location.href="https://baidu.com"; //跳转地址
}</script>
话不多说了,上PHP屏蔽代码
<?php
function strexists2($string, $find) { return !(strpos($string, $find) === false); }
function deep_in_array2($value, $array) {
foreach($array as $item) {
if(!is_array($item)) {
if (strpos($value, $item) !== false) {
return true;
} else { continue; } }
if(in_array($value, $item)) {
return true;
} else if(deep_in_array($value, $item)) {
return true;
}
} return false; }
function mobile() {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
$ualist = array('android', 'midp', 'nokia', 'mobile', 'iphone', 'ipod', 'blackberry', 'windows phone');
if((deep_in_array2($useragent, $ualist) || strexists2($_SERVER['HTTP_ACCEPT'], "VND.WAP") || strexists2($_SERVER['HTTP_VIA'],"wap")))
if(strpos($useragent,'iphone')!==false||strpos($useragent,'ipod')!==false) return '苹果'; else return '安卓';
else
return '电脑'; }
if(mobile()=='电脑'){ exit(header("location:https://baidu.com")); } //跳转地址