作者 邓超

redirect

@@ -19,6 +19,7 @@ class Controller extends BaseController @@ -19,6 +19,7 @@ class Controller extends BaseController
19 * @time 2023/1/16 9:22 19 * @time 2023/1/16 9:22
20 */ 20 */
21 public function redirect($url){ 21 public function redirect($url){
  22 + $url = urldecode($url);
22 if(!preg_match("/^http(s?):\/\//",$url)){ 23 if(!preg_match("/^http(s?):\/\//",$url)){
23 $url = 'http://'.$url; 24 $url = 'http://'.$url;
24 } 25 }
@@ -134,6 +134,20 @@ class Index extends Base @@ -134,6 +134,20 @@ class Index extends Base
134 if(!is_dir(dirname($filename))){ 134 if(!is_dir(dirname($filename))){
135 mkdir(dirname($filename),0775,true); 135 mkdir(dirname($filename),0775,true);
136 } 136 }
  137 +
  138 + // 是否有第三方连接
  139 + if (
  140 + preg_match_all(
  141 + "/<a[\s\t]*href[\s\t]*=[\s\t]*\"[\s\t]*(http[s]?:\/\/.*)[\s\t]*\"/Ui",
  142 + $data['html'],
  143 + $urls)
  144 + ){
  145 + foreach ($urls[1] as $k=>$url){
  146 + $_url = str_replace($url,'/redirect-'.urlencode($url),$urls[0][$k]);
  147 + $data['html'] = str_replace($urls[0][$k],$_url,$data['html']);
  148 + }
  149 + }
  150 +
137 @file_put_contents($filename,$data['html']); 151 @file_put_contents($filename,$data['html']);
138 152
139 } 153 }