After logging on to php, jump back to the page to be accessed. example _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
After logging on to php, you can jump back to the page instance you were visiting. Many website users first visit a page to log on, but at that time they did not log on and then log on. after the user logs on successfully, they certainly want to return to the last accessed page, now, many website users access a page to log on, but they did not log on and then log on. after the user successfully logs on, they certainly want to return to the last accessed page, next, I will introduce you to the page instance you want to access after logging on.

The simplest way is to directly use php $ _ SERVER ['http _ referer']


If I want to log on to the. php page


Now, go to the B. php page and add the following code in B. php:

The code is as follows:

$ Url = $ _ SERVER ['http _ referer'];
Header ("location: $ url ");

However, there are many deficiencies in the above method, such as parameters. but in IE browser, if you are redirecting through js location, this value cannot be obtained.

Here is a comprehensive example.


First, create a method to determine whether to log on. if not

The code is as follows:

Protected function checkLogin (){
If (no logon ){
$ Thisurl = "http: //". $ _ SERVER ["HTTP_HOST"]. $ _ SERVER ['php _ SELF ']; // The current URL
$ Thisurl = urlencode ($ thisurl); // you must transcode the obtained url. Otherwise, it is difficult to transmit the URL later.
Redirect ("http: //". $ _ SERVER ["HTTP_HOST"]. "/cityosweb/default. php/Index/login? Url = ". $ thisurl );
}
}

Then, you can call this method on the page on which you need to log on:

The code is as follows:

$ This-> checkLogin ();

In this way, if you do not log on, you will be redirected to the logon page. With the url of your previous page:


Then obtain the URL and submit the logon request:

The code is as follows:

Public function login (){
$ Url = $ _ GET ['URL'];
$ This-> assign ('URL', $ url );
$ This-> assign ('title', 'login ');
$ This-> display ('user/reg_new.html ');
}

After obtaining the url from the template, submit it to the php background. after logging on, jump to this url and OK.

...

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.