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

Source: Internet
Author: User

Project requirements

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 Idea 1:

Before jumping to the login page, save the URL of the current access page to the cookie, and after the login authentication authorization is passed, remove the URL value from the cookie and jump to the page specified by the URL.

Concrete implementation

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.

Copy Code code as follows:

$refer = ' http://'. $_server [' Http_host ']. $_server[' Request_uri '];
Cookie::set (' refer ', $refer);

Login to detect the function inside we join:

Copy Code code as follows:

$refer = Cookie::get (' refer ');

Now this $refer is our previous visit to the page, we can return this parameter via Ajax, and then jump, or directly using the program to jump, depending on the needs of your program.

Workaround 2:
 
In addition to the form of cookies, I believe you have seen many large web sites directly in the form of get, Drupal's landing mechanism is this.
This idea is specific:
to pass the URL of a page visited by a visitor before jumping to the login page as a parameter, after the login is authenticated, the access permission is granted to the page specified by the URL.
For example, the URL before login 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 the parameter Openphp.html, login verification successful jump to openphp.html this page is OK.

Roughly I also have these two ideas, if you have a better idea, I really 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.