Last active
April 5, 2016 09:09
-
-
Save azhurb/7df724a3b3d470668d50941140e2e244 to your computer and use it in GitHub Desktop.
Nginx secure link for Custom URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: server/lib/vod.class.php | |
| IDEA additional info: | |
| Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
| <+>UTF-8 | |
| =================================================================== | |
| --- server/lib/vod.class.php (date 1459783782000) | |
| +++ server/lib/vod.class.php (revision ) | |
| @@ -1032,6 +1032,24 @@ | |
| $replace_str = $tmp_arr[1].str_pad($series, 2, '0', STR_PAD_LEFT ); | |
| $url = str_replace($search_str, $replace_str, $url); | |
| } | |
| + | |
| + $secret = Config::get('nginx_secure_link_secret'); | |
| + | |
| + if(preg_match('/http(s)?:\/\/([^\/]+)\/(.+)$/', $url, $match)){ | |
| + $uri = '/'.$match[3]; | |
| + }else{ | |
| + $uri = ''; | |
| + } | |
| + | |
| + $remote_addr = $this->stb->ip; | |
| + $expire = time() + Config::getSafe('vclub_nginx_tmp_link_ttl', 7200); | |
| + | |
| + $hash = base64_encode(md5($secret.$uri.$remote_addr.$expire, true)); | |
| + | |
| + $hash = strtr($hash, '+/', '-_'); | |
| + $hash = str_replace('=', '', $hash); | |
| + | |
| + $url .= (strpos($url, '?') !== false ? '&' : '?') . 'st='.$hash.'&e='.$expire; | |
| return $url; | |
| } | |
| } | |
| \ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment