How to complete PHP login and jump to the previous page visited: 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, remove this from the cookie. URL value; 2. Before jumping to the login page, the URL of the page visited by the visitor must be passed as a parameter.
[Related learning recommendations:php programming(video)]
PHP login completed Method to jump to the previous visited page:
Solution 1:
Before jumping to the login page, save the URL of the currently visited page to In the cookie, after the login verification authorization is passed, the url value is taken out from the cookie and jumps to the page specified by the url.
Specific implementation
Based on the ThinkPHP framework, there will be a parent class controller.
Add this cookie setting code to the_initialize()
function in this BaseAction.
Code:
Code example:
$refer = 'http://' . $_SERVER ['HTTP_HOST'] . $_SERVER['REQUEST_URI']; Cookie::set('refer', $refer);
Add to the login detection function:
Code example:
$refer = Cookie::get('refer');
Now this$refer
is the page visited before. You can return this parameter through AJAX and then jump, or Use the program directly to jump.
Solution 2:
In addition to saving in the form of cookies, many large websites directly obtain it in the form of GET. This is the login mechanism of Drupal.
Implementation idea:
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 specified URL page.
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 islogin.php?url=openphp .html
, so that you can use the GET method to obtain the parameter openphp.html when logging in. After successful login verification, you can jump to the openphp.html page.
[Related learning recommendations:php graphic tutorial]
The above is the detailed content of How to complete login in PHP and jump to the previous visited page. For more information, please follow other related articles on the PHP Chinese website!