ThinkPHP's redirect jump and referer usage issues

WBOY
Release: 2023-03-02 13:12:02
Original
4387 people have browsed it

If you jump from the Topic/topic page to the Login/login page using $_SERVER['HTTP_REFERER'] and then log in, the address of the page will be like this http://localhost/a/jz/index .php/Home/topic/topic, this address is correct, why does the address on the address bar become like this after I use redirect? http://localhost/a/jz/index.php/a/jz /index.php/Home/Login/login.html? And why is this jump address not the address previously stored in the session?

ThinkPHP's redirect jump and referer usage issues

<code>以下是login控制器下login操作方法跳转部分的代码
$url=$_SERVER['HTTP_REFERER'];
session('url',$url);
var_dump(session('url'));
if(!isset(session('res2')[0])){  //验证通过产生的session是否存在
    $this->display();            //不存在session还显示login页面
}else{
    $this->redirect(session('url')); //存在则跳转
}</code>
Copy after login
Copy after login
Reply content:

If you jump from the

Topic/topic page to the Login/login page using $_SERVER['HTTP_REFERER'] and then log in, the address of the page will be like this http://localhost/a/jz/index .php/Home/topic/topic, this address is correct, why does the address on the address bar become like this after I use redirect? http://localhost/a/jz/index.php/a/jz /index.php/Home/Login/login.html? And why is this jump address not the address previously stored in the session?

<code>以下是login控制器下login操作方法跳转部分的代码
$url=$_SERVER['HTTP_REFERER'];
session('url',$url);
var_dump(session('url'));
if(!isset(session('res2')[0])){  //验证通过产生的session是否存在
    $this->display();            //不存在session还显示login页面
}else{
    $this->redirect(session('url')); //存在则跳转
}</code>
Copy after login
Copy after login
ThinkPHP's redirect jump and referer usage issues It should be a problem handled by

$this->redirect

Method 1: Use

str_replace

to remove the previous part of the content obtained by $_SERVER['HTTP_REFERER']$url = str_replace('http://localhost/a/jz/index.php','' ,$url); Method 2: Instead of using

$this->redirect(session('url'));

jump, use header('location:'.session('url'));exit();

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template