Home >Backend Development >PHP Tutorial >Use PHP to jump to the previous page after logging in
This article mainly introduces the use of PHP to jump to the previous access page after logging in. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
Visit the website page Sometimes, some pages require authorization to access. At this time, the user will be asked to log in and jump to the login page login.php. How to return to the page just visited after logging in
Project requirements
When accessing website pages, some pages require authorization to access. At this time, the user will be asked to log in and jump to the login page login.php. How to return to the page just visited after logging in.
Solution 1:
Before jumping to the login page, save the URL of the currently visited page in the cookie. After the login verification authorization is passed, take out the URL value from the cookie and jump Go to the page specified by this url.
Specific implementation
My current program is based on the ThinkPHP framework. We will have a parent class controller. Next, I will add the code for setting cookies to _initialize in the BaseAction. () function, this greatly simplifies the workload of the program.
$refer = 'http://' . $_SERVER ['HTTP_HOST'] . $_SERVER['REQUEST_URI']; Cookie::set('refer', $refer);
In the login detection function, we add:
$refer = Cookie::get('refer');
Now this $refer is the page we visited before. We can return this parameter through AJAX, and then jump, or directly use the program Jumping depends on the needs of your program.
Solution 2:
In addition to saving in the form of cookies, I believe you have also seen that many large websites directly use GET to obtain data. This is the login mechanism of Drupal.
The specific idea is this:
Before jumping to the login page, the URL of the page visited by the visitor must be passed as a parameter. After login verification, after granting access rights, jump to the page specified by the URL. .
For example, the url before login is: openphp.html. When a visitor visits and clicks "No permission", the address that jumps to the login page is login.php?url=openphp.html, so that the GET method can be used when logging in. Get the parameter openphp.html and jump to the openphp.html page after successful login verification.
Generally speaking, I have these two ideas. If you have a better idea, I really hope you can tell me.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to use PHP to enable SWOOLE extension to synchronize MySQL data regularly
##How to bypass open_basedir through PHP Restrict operating files
The above is the detailed content of Use PHP to jump to the previous page after logging in. For more information, please follow other related articles on the PHP Chinese website!