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, next, I will introduce you to the simple way to jump back to the page instance to be accessed after logon. The simplest way is to directly use ph...
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, 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.