12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace app\index\controller;
- use app\index\model\ShortUrlModel;
- use think\Controller;
- use think\Validate;
- class Index extends Controller
- {
- /**
- * 短链接进入接口
- */
- public function index(){
- $params = $this->request->param();
- $rule = [
- 'to'=>'require'
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- header('HTTP/1.1 400 [to]');
- exit;
- }
- $shortUrlModel = new ShortUrlModel();
- $res = $shortUrlModel->where(['url_str'=>"{$params['to']}"])->find();
- if(empty($res)){
- header('HTTP/1.1 400 [url_str]');
- exit;
- }
- $url = base64_decode($res['old_url']);
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: $url");
- exit;
- }
- }
|