diff --git a/helper.php b/helper.php index 0c6dc504..0a3206fd 100644 --- a/helper.php +++ b/helper.php @@ -426,7 +426,7 @@ function xml($data = [], $code = 200, $options = []) * @param array $params 额外参数 * @return \think\response\Redirect */ -function redirect($url = [], $code = 200, $params = []) +function redirect($url = [], $code = 302, $params = []) { return Response::create($url, 'redirect')->code($code)->params($params); } diff --git a/library/think/Session.php b/library/think/Session.php index 1889cef5..35de1bfa 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -206,7 +206,6 @@ class Session * @param string $name session名称 * @param string|null $prefix * @return bool - * @internal param mixed $value session值 */ public static function has($name, $prefix = null) { diff --git a/library/think/response/Redirect.php b/library/think/response/Redirect.php index 4deac9e9..c60c007f 100644 --- a/library/think/response/Redirect.php +++ b/library/think/response/Redirect.php @@ -11,7 +11,9 @@ namespace think\response; +use think\Request; use think\Response; +use think\Session; use think\Url; class Redirect extends Response @@ -30,10 +32,9 @@ class Redirect extends Response */ protected function output($data) { - $this->isExit = true; $url = preg_match('/^(https?:|\/)/', $data) ? $data : Url::build($data, $this->params); $this->header['Location'] = $url; - $this->header['status'] = isset($this->header['status']) ? $this->header['status'] : 301; + $this->header['status'] = isset($this->header['status']) ? $this->header['status'] : 302; $this->header['Cache-control'] = 'no-cache,must-revalidate'; return; } @@ -43,4 +44,23 @@ class Redirect extends Response $this->params = $params; return $this; } + + /** + * 记住当前url后跳转 + */ + public function remember() + { + Session::set('redirect_url', Request::instance()->url()); + } + + /** + * 跳转到上次记住的url + */ + public function restore() + { + if (Session::has('redirect_url')) { + $this->data = Session::get('redirect_url'); + Session::delete('redirect_url'); + } + } }