Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to jump to the previous page in php

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to jump to the previous page in php, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Php to achieve the method to jump to the previous page: 1, save the url of the current visited page to cookie, then take the url value from cookie, jump to the page specified by the url; 2, pass the url of the page visited by the visitor as a parameter, and jump to the page specified by the url after granting access.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php jump to the previous page?

How to jump to the previous access page after PHP login is completed

Project requirements

When visiting the website page, some pages need authorization to access, at this time will require the user to log in, jump to the login page login.php, how to log in and return to the page you just visited.

Solution idea 1:

Save the url of the current access page to cookie before jumping to the login page. After the login verification authorization is passed, take the url value from the cookie and jump to the page specified by the url.

Concrete realization

My current program is based on the ThinkPHP framework, we will have a parent controller, so I will add the code to set cookie to the _ initialize () function in this BaseAction, so the program will greatly simplify the workload.

The code is as follows:

$refer = 'http://'. $_ SERVER ['HTTP_HOST']. $_ SERVER ['REQUEST_URI']; Cookie::set (' refer', $refer)

In the login detection function, we add:

The code is as follows:

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

Now this $refer is the page we visited before, we can return this parameter through AJAX, and then jump, or directly use the program to jump, depending on the needs of your program.

Solution 2:

In addition to saving in the form of cookie, I believe you have also seen that many large websites are directly obtained in the form of GET, and this is the login mechanism of Drupal.

The idea goes like this:

Pass the url of the page visited by the visitor as a parameter before jumping to the login page. After login verification, jump to the page specified by the url after granting access.

For example, the url before login is: openphp.html when visitors visit, click without permission, and the address to jump to the login page is login.php?url=openphp.html, so that you can obtain the parameter openphp.html by GET when logging in. After successful login verification, you can jump to the openphp.html page.

About how to jump to the previous page in php to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report