本文将介绍如何通过 PHP 函数处理,轻松生成制作各种第三方下载工具(比如迅雷,快车,QQ旋风)的下载链接数据,并直接输出到前台上,同时也可以将转换过的链接还原为原始的下载地址。
该功能所用到的 PHP 函数主要是下面两个:
1. base64_encode: 用于以 base64 方式加密字符串;
2. base64_decode: 用于解密以 base64 方式加密的字符串。
下面直接通过示例说明,基本都能理解,就不做详细解释了。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>PHP生成迅雷、快车、QQ旋风下载链接的方法</title>
</head>
<body>
<?php
function zhuanhuan($url){
if(empty($url)) return $result;
$urlodd=explode('//',$url,2);
$head=strtolower($urlodd[0]);
$behind=$urlodd[1];
if($head=="thunder:"){
$url=substr(base64_decode($behind),2,-2);
}else if($head=="flashget:"){
$url1=explode('&',$behind,2);
$url=substr(base64_decode($url1[0]),10,-10);
}else if($head=="qqdl:"){
$url=base64_decode($behind);
}else if($head=="http:"||$head=="ftp:"||$head=="mms:"||$head=="rtsp:"||$head=="https:"){
$url=array(
'thunder'=>"thunder://".base64_encode("AA".$url."ZZ"),
'flashget'=>"Flashget://".base64_encode("[FLASHGET]".$url."[FLASHGET]")."&aiyh",
'qqdl'=>"qqdl://".base64_encode($url)
);
}else{
return '';
}
return $url;
}
$url=isset($_GET['url'])?$_GET['url']:'';
$result=zhuanhuan($url);
?>
<form action="" method=GET>
请输入普通链接或者迅雷,快车,旋风链地址:<br />
<input type=text name="url" size="80">
<input type=submit value="转换">
</form>
<?php
if(is_array($result)){//www.feishuai.vip
?>
<p>地址:<a href="<?php echo $url;?>" target="_blank"><?php echo $url;?></a>
<p>迅雷链:<a href="<?php echo $result['thunder'];?>" target="_blank"><?php echo $result['thunder'];?></a>
<p>快车链:<a href="<?php echo $result['flashget'];?>" target="_blank"><?php echo $result['flashget'];?></a>
<p>旋风链:<a href="<?php echo $result['qqdl'];?>" target="_blank"><?php echo $result['qqdl'];?></a>
<?php
}else{
?>
<p>实际地址:<a href="<?php echo $result;?>" target="_blank"><?php echo $result;?></a>
<?php
}
?>
</body>
</html>
页面的效果如下图: