php提取MYSQL数据的url_PHP获取跳转后的URL,存到数据库,设置缓存时间

$accessToken='b452d6669d7d41efabd92190c1f1c2d9'; //这里填写你自己帐号捉包的accessToken

//连接数据库查询FID是否有数据,并且是否有效

//表自己建吧,就几个自动

$btime=$limittime*1000;//获取毫秒数

$stime=time();//开始时间

$etime=time()+$btime;//结束时间

//查询下FID是否有数据

$sql="select count(*) as total from url_table where fid='".$fid."' and down_url!='http:&ctyunapi.cn'";$result=mysql_query($sql);$data=mysql_fetch_array($result);$total=$data[0]['total'];if($total>0){//如果有数据,校验下,是否有效

$sql="select count(*) as total from url_table where fid='".$fid."' and stime>=".$btime." and etime<=".$btime;$result=mysql_query($sql);$data=mysql_fetch_array($result);$totalt=$data[0]['total'];if($totalt<1){//更新获取的数据

//获取下载地址

$data=get_curl_contents('https://api.cloud.189.cn/loginByOpen189AccessToken.action?accessToken='.$accessToken);preg_match('|sessionKey>(.*)(.*)

}else{$videos='http:'.getrealurl($video).'&ctyunapi.cn';

}$down_url=getrealurl($videos);$sql="update url_table set down_url='".$down_url."',stime=".$stime.",etime=".$etime." where fid=".$fid;mysql_query($sql);

}else{$sql="select down_url from url_table where fid='".$fid."' and stime>=".$btime." and etime<=".$btime;$result=mysql_query($sql);$data=mysql_fetch_array($result);$down_url=$data[0]['down_url'];

}

}else{//直接插入数据

$data=get_curl_contents('https://api.cloud.189.cn/loginByOpen189AccessToken.action?accessToken='.$accessToken);preg_match('|sessionKey>(.*)(.*)

}else{$videos='http:'.getrealurl($video).'&ctyunapi.cn';

}$down_url=getrealurl($videos);$sql="insert into url_table(fid,stime,etime,down_url)values('".$fid."',".$stime.",".$etime.",'".$down_url."')";mysql_query($sql);

}mysql_close($conn);header("Location:$down_url");function get_curl_contents($url,$header=0,$nobody=0){if(!function_exists('curl_init')) die('php.ini未开启php_curl.dll');$c =curl_init();

curl_setopt($c, CURLOPT_URL, $url);

curl_setopt($c, CURLOPT_HEADER, $header);

curl_setopt($c, CURLOPT_NOBODY, $nobody);

curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($c, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

curl_setopt($c, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

curl_setopt($c, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$_SERVER["REMOTE_ADDR"], 'CLIENT-IP:'.$_SERVER["REMOTE_ADDR"]));$content = curl_exec($c);

curl_close($c);return $content;

}function getrealurl($url){$header = get_headers($url,1);if (strpos($header[0],'301') || strpos($header[0],'302')) {if(is_array($header['Location'])) {return $header['Location'][count($header['Location'])-1];

}else{return $header['Location'];

}

}else{return $url;

}

}?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值