帝国CMS判断下载地址或者百度网盘分享连接已经失效的方法。温馨提示:此方法仅供插件开发参考!如需要插件请联系站长!下面来段代码放在根目录测试下吧。
小编只是给需要的朋友提供一个方法。代码已经注释说明请按照您的需求进行插件开发吧!!!
效果图:
- <?php
- //设置最大执行时间是 120秒
- ini_set('max_execution_time',120);
- require('e/class/connect.php');
- require('e/class/db_sql.php');
- require('e/data/dbcache/class.php');
- $link=db_connect();
- $empire=new mysqlquery();
- $wzurl="https://www.meiweny.cn";//自己的网站地址
- // 监测链接能否正常访问
- function httpcode($url){
- $ch = curl_init();
- $timeout = 5;
- $user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
- curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_REFERER, $wzurl);
- curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
- $results=curl_exec($ch);
- $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
- if($httpcode= 200) {
- if(strpos($results,'链接不存在')||$results=''||strpos($results,'404')){
- return '地址失效!!!';
- }else{
- return '地址正常';
- }
- }else{
- return $httpcode;
- }
- curl_close($ch);
- }
- // 要监测的链接数组
- $sql=$empire->query("select * from {$dbtbpre}ecms_download order by newstime desc limit 20 "); //查询下载数据表最新20条信息
- $downpath=array();
- while($r=$empire->fetch($sql)){
- $finfor=$empire->fetch1("select * from {$dbtbpre}ecms_download_data_".$r['stb']." where id='$r[id]' limit 1");
- $finfor['downpath']=$finfor['downpath'].$r['title'].$r['id'];
- $downpath[]=explode("::::::",$finfor['downpath']);
- }
- //区分下载地址
- foreach ($downpath as $key => $value) {
- if(strpos($value[1],'https://') === 0){
- $url=$value[1];
- }else{
- $url=$wzurl.$value[1];
- }
- echo '编号:'.$key.'->标题:'.$value[4].' ->地址: '.$url.' ->状态: '.httpcode($url).'<br>';
- //以下为JSON输出可以注释
- /*
- echo json_encode( [
- "bianhao" => $key,
- "title"=>$value[4],
- "titleurl"=>$url,
- "status" =>httpcode($url),
- ] );
- */
- }
小编只是给需要的朋友提供一个方法。代码已经注释说明请按照您的需求进行插件开发吧!!!