When you access a website page, some pages must be authorized to access. At this time, you are required to log on to the login. php logon page. How can I return to the accessed page after logon?
When you access a website page, some pages must be authorized to access. At this time, you are required to log on to the login. php logon page. How can I return to the accessed page after logon?
Project requirements
When you access a website page, some pages must be authorized to access. At this time, you are required to log on to the login. php logon page. How can I return to the accessed page after logon.
Solution 1:
Before you jump to the logon page, you need to save the url of the current access page to the cookie. After the authentication passes, you can retrieve the url value from the cookie to go to the page specified by the url.
Implementation
My current program is based on the ThinkPHP framework. We will have a parent class controller. Next I will add the cookie setting code to the _ initialize () function in this BaseAction, in this way, the workload is greatly simplified.
The Code is as follows:
$ Refer = 'HTTP: // '. $ _ SERVER ['HTTP _ host']. $ _ SERVER ['request _ URI'];
Cookie: set ('Referer', $ referers );
In the login detection function, we add:
The Code is as follows:
$ Refer = Cookie: get ('Referer ');
Now, $ refer is the page we visited. We can return this parameter through AJAX, and then jump to the page, or directly use the program to jump to the page, depending on your program needs.
Solution 2:
In addition to the cookie format, we believe that many large websites are directly obtained through GET. This is the Login Mechanism of Drupal.
The specific idea is as follows:
Before you jump to the logon page, you must pass the url of the page accessed by the visitor as a parameter. After logon verification, grant the access permission and go to the page specified by the url.
For example, the url before logon is openphp.html. When a visitor accesses openphp.html, the address displayed on the logon page is login. php? Url=openphp.html, so that you can use the GET method to obtain the parameter openphp.html during logon. After successful verification, you can access the openphp.html page.
In general, I have these two ideas. If you have a better idea, I sincerely hope you can tell me.