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.