前言:看见大佬们的博客缩略图都贼好看,我这个小白也想这么快乐,所以在学习了一些以后跟大家一起分享
随机二次元api地址:https://www.lechiqy.com/img.php
本站默认强制HTTPS
#2020年3月13日更新,手机随机图片共收录:19张,电脑端共收录:19张。#
-------分----------割------------线-------
在这里分享一下index.php,PE.php,PC.php这三个文件的源代码,供大家参考使用:
#INDEX.PHP文件源代码:
<?php //用php判断用户通过电脑端还是手机端访问网站 function isMobile(){ $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ”; $useragent_commentsblock=preg_match('|(.*?)|',$useragent,$matches)>0?$matches[0]:”; function CheckSubstrs($substrs,$text){ foreach($substrs as $substr) if(false!==strpos($text,$substr)){ return true; } return false; } $mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ'); $mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod'); $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) || CheckSubstrs($mobile_token_list,$useragent); if ($found_mobile){ return true; }else{ return false; } } //电脑端访问网站则打开PC.php文件 $pc = 'https://www.lechiqy.com/img/PC.php'; //手机端访问网站则打开PE.php文件 $pe = 'https://www.lechiqy.com/img/PE.php'; if (isMobile()){ header("Location:".$pe); }else{ header("Location:".$pc); } ?>
#PE.PHP,PC.PHP文件源代码(这两个文件的源代码都一样,我只发一个PC.PHP的供参照):
<?php // 在第四行代码中(1,9),的意思是:从1-9的链接中随机调用 $id=rand(1,9); //--------------------- //找规律的时间到了: //输入你要调用的图片的链接: //格式自己看下面代码,自己慢慢领会: $image[1]='https://www.lechiqy.com/img/1.jpeg'; $image[2]='https://www.lechiqy.com/img/2.jpeg'; $image[3]='https://www.lechiqy.com/img/3.jpeg'; $image[4]='https://www.lechiqy.com/img/4.jpeg'; $image[5]='https://www.lechiqy.com/img/5.jpeg'; $image[6]='https://www.lechiqy.com/img/6.jpeg'; $image[7]='https://www.lechiqy.com/img/7.jpeg'; $image[8]='https://www.lechiqy.com/img/8.jpeg'; $image[9]='https://www.lechiqy.com/img/9.jpeg'; header("location:$image[$id]"); ?>
还有什么不懂的可以在底下留言,我尽量快速回复
Original article, reproduced please specify:随机二次元图片API接口,PHP随机调用文件夹下的图片 | 青尢Blog