How to jump to the previous access page after logging on to PHP

Source: Internet
Author: User
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.

Related Article

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.