作者 邓超

redirect

... ... @@ -19,6 +19,7 @@ class Controller extends BaseController
* @time 2023/1/16 9:22
*/
public function redirect($url){
$url = urldecode($url);
if(!preg_match("/^http(s?):\/\//",$url)){
$url = 'http://'.$url;
}
... ...
... ... @@ -134,6 +134,20 @@ class Index extends Base
if(!is_dir(dirname($filename))){
mkdir(dirname($filename),0775,true);
}
// 是否有第三方连接
if (
preg_match_all(
"/<a[\s\t]*href[\s\t]*=[\s\t]*\"[\s\t]*(http[s]?:\/\/.*)[\s\t]*\"/Ui",
$data['html'],
$urls)
){
foreach ($urls[1] as $k=>$url){
$_url = str_replace($url,'/redirect-'.urlencode($url),$urls[0][$k]);
$data['html'] = str_replace($urls[0][$k],$_url,$data['html']);
}
}
@file_put_contents($filename,$data['html']);
}
... ...