In some resource download sharing sites, we often encounter the need to add various download tool links on the download page. The traditional method of generating links using scripts (. js) officially provided by various download tools has become increasingly prominent, such as slow loading and client compatibility issues.
This article describes how to use PHP functions to easily generate links for various third-party download tools and output them directly to the front-end.
PHP functions used by this function:
1. base64_encode: used to encrypt strings in base64 mode;
2. base64_decode: used to decrypt strings encrypted in base64 mode.
Example 1
Generate a third-party tool download link with the original download address. PHP code:
The code is as follows: |
Copy code |
$ Url = 'http: // www.example.com/document.zip '; // You can refer to the following code to find the exact structure of download links for various third-party tools: $ Url_thunder = 'Thunder: // '. base64_encode ('AA'. $ url. 'Zz '); $ Url_flashget = 'flashget: // '. base64_encode (' [flashget] '. $ url.' [FLASHGET] '); $ Url_qqdl = 'qqdl: // '. base64_encode ($ url ); |
Download the link from a third-party tool and restore it to the original link PHP code:
The code is as follows: |
Copy code |
$ Url_old = ''; // Separate the string // $ Temp = explode ('//', $ url_old, 2 ); // Determine // the character before (converted to lowercase) 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; } |
Example 2
The code is as follows: |
Copy code |
<? Php Function zhuanhuan (){ $ Urlodd = explode ('/', $ _ GET ["url"], 2); // divide the link into two sections. // The first section is the first section, followed by the second paragraph $ Head = strtolower ($ urlodd [0]); // PHP is case sensitive, which is first converted to lowercase. Otherwise, HtTp: or ThUNDER: is not easy to handle. $ Behind = $ urlodd [1]; If ($ head = "thunder :"){ $ Url = substr (base64_decode ($ behind), 2,-2); // base64 decryption, remove the preceding AA and the following ZZ } Elseif ($ head = "flashget :"){ $ Url1 = explode ('&', $ behind, 2 ); $ Url = substr (base64_decode ($ url1 [0]), 10,-10); // base64 decryption, remove the previous [FLASHGET] } Elseif ($ head = "qqdl :"){ $ Url = base64_decode ($ behind); // base64 decryption } Elseif ($ head = "http:" | $ head = "ftp:" | $ head = "mms:" | $ head = "rtsp: "| $ head =" https :"){ $ Url = $ _ GET ["url"]; // The regular address only supports the http, https, ftp, mms, and rtsp transmission protocols. It seems that few other addresses are supported, A network disk like XX is actually based on base64, but some cannot be downloaded even after decryption. } Else { Echo "this page does not support this protocol currently "; } Return $ url; } If ($ _ GET ["url"]! = NULL ){ $ Url = zhuanhuan ($ _ GET ["url"]); $ Url_thunder = "thunder: //". base64_encode ("AA". $ url. "ZZ"); // base64 encryption, the same is true for the following 2 $ Url_flashget = "Flashget: //". base64_encode ("[FLASHGET]". $ url. "[FLASHGET]"). "& aiyh "; $ Url_qqdl = "qqdl: //". base64_encode ($ url ); } ?> <Form action = cs. php method = GET> Enter a normal link or an express or tornado link address: <Input type = text name = "url" size = "80"> <Input type = submit value = "conversion"> </Form> <P> actual address: <a href = "<? Php echo $ url;?> "Target =" _ blank "> <? Php echo $ url;?> </A> <P> Thunder Chain: <a href = "<? Php echo $ url_thunder;?> "Target =" _ blank "> <? Php echo $ url_thunder;?> </A> <P> express chain: <a href = "<? Php echo $ url_flashget;?> "Target =" _ blank "> <? Php echo $ url_flashget;?> </A> <P> tornado chain: <a href = "<? Php echo $ url_qqdl;?> "Target =" _ blank "> <? Php echo $ url_qqdl;?> </A> |
The generated results are as follows: