-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathquick-direct.php
More file actions
47 lines (39 loc) · 972 Bytes
/
Copy pathquick-direct.php
File metadata and controls
47 lines (39 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Created by PhpStorm.
* User: Youi
* Date: 2016-01-14
* Time: 22:22
*/
/**
* urlencode url components
* @param $url
* @return string
*/
function encodeCjkChars($url) {
if (preg_match('<(http.+?tumblr\.com)(.+$)>i', $url, $matches)) {
$path_parts = array_map('urlencode', explode('/', $matches[2]));
$url = $matches[1] . implode('/', $path_parts);
}
return $url;
}
/**
* hash sting into a given number range
* @param $str
* @param $maxRange
* @return number
*/
function strHash($str, $maxRange) {
$strValue = crc32($str);
return abs($strValue % $maxRange) + 1;
}
$numberOfHost = 4;
if (isset($_GET['url'])) {
$hashNode = strHash($_GET['url'], $numberOfHost);
$redirectUrl = "http://tumblr-images-$hashNode.appspot.com/main.php?url={$_GET['url']}";
$redirectUrl = encodeCjkChars($redirectUrl);
header('Location: ' . $redirectUrl, true, 301);
}
else {
echo 'Hello Tumblr!!';
}