Home >Backend Development >PHP Problem >How to jump to the previous page in php
How to jump to the previous page in php: 1. Save the url of the currently visited page in the cookie, then take out the url value from the cookie and jump to the page specified by the url; 2. Pass the URL of the page visited by the visitor as a parameter, and jump to the page specified by the URL after granting access permission.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to jump to the previous page in php Page?
How to jump to the previous visited page after PHP login is completed
Project requirements
When visiting the website page , 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 a cookie. After the login verification authorization is passed, the url value is retrieved from the cookie and jumps to the page specified by the url.
Specific implementation
My current program is based on the ThinkPHP framework. We will have a parent class controller. Now I will add the code to set the cookie. In the _initialize() function in this BaseAction, this program greatly simplifies the workload.
The code is as follows:
$refer = 'http://' . $_SERVER ['HTTP_HOST'] . $_SERVER['REQUEST_URI']; Cookie::set('refer', $refer);
In the login detection function we add:
The code is as follows:
$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 to jump, depending 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 them. This is the login mechanism of Drupal. .
The specific idea is as follows:
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 permission, 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.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to jump to the previous page in php. For more information, please follow other related articles on the PHP Chinese website!