PHP生成迅雷、快车、QQ旋风下载链接的实例
在一些资源下载共享站点中,我们经常遇到需要在下载页中添加各种下载工具链接的情况。传统的利用各下载工具官方提供的脚本(.js)生成链接的方式,其弊端已日渐突出,如加载速度慢、客户端兼容性问题等。
本文将介绍如何通过 PHP 函数处理,轻松生成制作各种第三方下载工具的链接数据,并直接输出到前台上。
该功能所用到的 PHP 函数:
1. base64_encode: 用于以 base64 方式加密字符串;
2. base64_decode: 用于解密以 base64 方式加密的字符串。
例子1
以原始下载地址生成第三方工具下载链接 PHP 代码:
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4037')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4037>$url = 'http://www.example.com/document.zip';
// 可从以下代码推知各种第三方工具下载链接的精确构成
$url_thunder = 'thunder://' . base64_encode ( 'AA' . $url . 'ZZ' );
$url_flashget = 'flashget://' . base64_encode ( '[FLASHGET]' . $url . '[FLASHGET]' );
$url_qqdl = 'qqdl://' . base64_encode ( $url );
从第三方工具下载链接还原成原始链接 PHP 代码:
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy9649')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9649>$url_old = '';
// 将字符串以 // 为界限分开
$temp = explode ( '//' , $url_old, 2 );
// 判断 // 前的字符(已转换为小写)
switch ( strtolower( $temp[0] ) ) {
case 'thunder:':
$url_new = substr ( base64_decode ( $temp[1] ), 2, -2 );
break;
case 'flashget:':
$url_new = substr ( base64_decode ( $temp[1] ), 10, -10 );
break;
case 'qqdl:':
$url_new = base64_decode ( $temp[1] );
break;
}
例子2
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5626')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5626><?php
function zhuanhuan() {
$urlodd=explode('//',$_GET["url"],2);//把链接分成2段,//前面是第一段,后面的是第二段
$head=strtolower($urlodd[0]);//PHP对大小写敏感,先统一转换成小写,不然 出现HtTp:或者ThUNDER:这种怪异的写法不好处理
$behind=$urlodd[1];
if($head=="thunder:"){
$url=substr(base64_decode($behind), 2, -2);//base64解密,去掉前面的AA和后面ZZ
}elseif($head=="flashget:"){
$url1=explode('&',$behind,2);
$url=substr(base64_decode($url1[0]), 10, -10);//base64解密,去掉前面后的[FLASHGET]
}elseif($head=="qqdl:"){
$url=base64_decode($behind);//base64解密
}elseif($head=="http:"||$head=="ftp:"||$head=="mms:"||$head=="rtsp:"||$head=="https:"){
$url=$_GET["url"];//常规地址仅支持http,https,ftp,mms,rtsp传输协议,其他地貌似很少,像XX网盘实际上也是基于base64,但是有的解密了也下载不了
}else{
echo "本页面暂时不支持此协议";
}
return $url;
}
if($_GET["url"]!=NULL){
$url=zhuanhuan($_GET["url"]);
$url_thunder="thunder://".base64_encode("AA".$url."ZZ");//base64加密,下面的2也一样
$url_flashget="Flashget://".base64_encode("[FLASHGET]".$url."[FLASHGET]")."&aiyh";
$url_qqdl="qqdl://".base64_encode($url);
}
?>
<form action=cs.php method=GET>
请输入普通链接或者迅雷,快车,旋风链地址:
<input type=text name="url" size="80">
<input type=submit value="转换">
</form>
<p>实际地址:<a href="<?php echo $url;?>" target="_blank"><?php echo $url;?></a>
<p>迅雷链:<a href="<?php echo $url_thunder;?>" target="_blank"><?php echo $url_thunder;?></a>
<p>快车链:<a href="<?php echo $url_flashget;?>" target="_blank"><?php echo $url_flashget;?></a>
<p>旋风链:<a href="<?php echo $url_qqdl;?>" target="_blank"><?php echo $url_qqdl;?></a>
生成效果如下
您可能感兴趣的文章:
PHP生成迅雷、快车、QQ旋风下载链接的实例
迅雷下载不了磁力链接解决方法
迅雷磁力链接下载失败3种解决方案
生成讯雷地址php代码
帝国下载内容页显示迅雷,快车加密地址标签
浏览器url调用并启动本地应用程序实例
QQ浏览器设置默认下载工具的方法
迅雷快鸟加速失败如何解决 迅雷快鸟加速失败解决办法
百度云盘如何设置使用迅雷下载文件
教您为帝国下载系统2.5添加迅雷快车专用链