|
1 | 1 | <?php |
2 | 2 |
|
3 | | -// error_reporting(E_ALL); |
4 | | -// ini_set('log_errors', true); |
| 3 | +error_reporting(E_ALL); |
5 | 4 |
|
| 5 | +header("X-Powered-By: URL Shortener"); |
6 | 6 | date_default_timezone_set('Asia/Shanghai'); |
7 | 7 | define('ROOT_PATH', __DIR__); |
8 | 8 | define('CACHE_TYPE', 'file'); // 支持REDIS OR FILE |
@@ -182,10 +182,10 @@ function hashToUrl($hash) |
182 | 182 | * |
183 | 183 | * @param $url |
184 | 184 | * @param string $encrypt_type |
185 | | - * @param string $extent |
| 185 | + * @param array $extent |
186 | 186 | * @return string |
187 | 187 | */ |
188 | | -function urlToShort($url, $encrypt_type = 'encrypt', $extent = '') |
| 188 | +function urlToShort($url, $encrypt_type = 'encrypt', $extent = []) |
189 | 189 | { |
190 | 190 | if (!preg_match('/^[A-z]+:\/\//i', $url)) { |
191 | 191 | $url = 'http://' . $url; |
@@ -727,13 +727,13 @@ function responseJavascript($requestId) |
727 | 727 | $response = json(__('url cannot be empty'), 500); |
728 | 728 | } else if (mb_strlen($url) > 2047) { |
729 | 729 | $response = json(__('Too long url'), 500); |
730 | | - } else if (mb_strlen($extent) > 10000) { |
| 730 | + } else if (!empty($extent) && mb_strlen(json_encode($extent)) > 10000) { |
731 | 731 | $response = json(__('Too much content'), 500); |
732 | 732 | } else { |
733 | | - $extent = json_decode($extent, true); |
734 | 733 | $response = urlToShort($url, $encrypt_type, isset($extent) && !empty($extent) ? $extent : []); |
735 | 734 | $response = json(__('Link created successfully'), 200, $response); |
736 | 735 | } |
| 736 | + header('Content-type:text/json;charset=utf-8'); |
737 | 737 | echo $response; |
738 | 738 | }); |
739 | 739 |
|
|
0 commit comments