简介
在写API界面的时候我突然有一个想法,那就是把所有的API都可以让各大站长自己搭建来使用,
不然我并不想发这个教学的,因为该代码很简单没有可说的内容,按照我说的步骤执行就可以使用了
代码及说明
说明步骤
- 在根目录创建一个Store文件夹里面含有Pc和Pe的子文件夹
- 在根目录创建一个api.php来存放我提供的代码即可
- 需要在个别目录放几张图片哦,不然代码扫描不到报错呀~
- $device = $_GET[‘device’];//设备
- if($device == null || $device == ‘auto’ || $device == ‘AUTO’){
- if(wp_is_mobile() == true){
- $img_array = glob(“Store/Pe/*.{gif,jpg,png}”,GLOB_BRACE);
- }else{
- $img_array = glob(“Store/Pc/*.{gif,jpg,png}”,GLOB_BRACE);
- }
- }else{
- if($device == ‘pc’ || $device == ‘Pc’ || $device == ‘PC’){
- $img_array = glob(“Store/Pc/*.{gif,jpg,png}”,GLOB_BRACE);
- }else if($device == ‘pe’ || $device == ‘Pe’ || $device == ‘PE’){
- $img_array = glob(“Store/Pe/*.{gif,jpg,png}”,GLOB_BRACE);
- }else{
- $img_array = glob(“Store/Pc/*.{gif,jpg,png}”,GLOB_BRACE);
- }
- }
- $img = array_rand($img_array);
- header(“Location:”.$img_array[$img]);
- //判断手机或者电脑
- function wp_is_mobile() {
- static $is_mobile = null;
- if ( isset( $is_mobile ) ) {
- return $is_mobile;
- }
- if ( empty($_SERVER[‘HTTP_USER_AGENT’]) ) {
- $is_mobile = false;
- } elseif ( strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Mobile’) !== false // many mobile devices (all iPhone, iPad, etc.)
- || strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Android’) !== false
- || strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Silk/’) !== false
- || strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Kindle’) !== false
- || strpos($_SERVER[‘HTTP_USER_AGENT’], ‘BlackBerry’) !== false
- || strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Opera Mini’) !== false
- || strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Opera Mobi’) !== false ) {
- $is_mobile = true;
- } else {
- $is_mobile = false;
- }
- return $is_mobile;
- }
暂无评论...