How to jump to the previous access page after PHP login completes

Source: Internet
Author: User
Tags require

Visit the Site page, some pages need authorization to access, this time will require users to login, jump to the login page login.php, how to achieve the login back to the page just visited

Project requirements to visit the site page, some pages need authorization to access, this time will require users to login, jump to the login page login.php, how to achieve the login back to the page just visited.   Solution 1: Before jumping to the login page to save the current access page URL to the cookie inside, login authentication authorization passed, remove the URL value from the cookie, jump to the URL specified by the page.   The implementation of my current program is based on the thinkphp framework, we will have a parent class controller, I will add this cookie code to the baseaction inside the _initialize () function, so that the program greatly simplifies the workload. The code is as follows: $refer = ' http://'. $_server [' Http_host ']. $_server[' Request_uri '];     Cookie::set (' refer ', $refer);     Login detection function Inside we add: The code is as follows: $refer = Cookie::get (' refer ');   Now this $refer is our previous visit to the page, we can return this parameter through Ajax, and then jump, or directly using the program to jump, depending on the needs of your program. Solution 2: In addition to the form of stored as cookies, I believe you have seen many large Web sites directly using Get form, Drupal's landing mechanism is this. The idea is this: before jumping to the login page, you pass the URL of the page visited by the visitor as a parameter, and after the login is authenticated, the user is granted access to the page specified by the URL. For example, before the login URL is: openphp.html When visitors visit, click No permissions, jump to the address of the login page is login.php?url=openphp.html, so that when you log in, you can get this parameter   Openphp.html, login verification successful jump to openphp.html this page is OK. In general I also on these two ideas, if you have a better idea, sincerely hope you can tell me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.