How to complete login in PHP and jump to the previous visited page

coldplay.xixi
Release: 2023-03-05 06:50:01
Original
2837 people have browsed it

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.

How to complete login in PHP and jump to the previous visited page

[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);
Copy after login

Add to the login detection function:

Code example:

$refer = Cookie::get('refer');
Copy after login

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 is login.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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!