$url = $_SERVER['HTTP_REFERER'];
header("location:$url");
代码如下 |
复制代码 |
protected function checkLogin() {
if (没有登录){
$thisurl = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];//当前URL
$thisurl = urlencode($thisurl);//这里要注意需要把获取到的url转码,不然后面不好传递URL
redirect("http://".$_SERVER["HTTP_HOST"]."/cityosweb/default.php/Index/login?url=".$thisurl);
}
}
|
However, the above method has many shortcomings, such as parameters, etc., but under the IE browser, if you jump through the location of js, then this value cannot be obtained.
代码如下 |
复制代码 |
$this->checkLogin();
|
Now I will make a comprehensive one.
First create a method to determine whether you are logged in, if not logged in
The code is as follows
|
Copy code
代码如下 |
复制代码 |
public function login() {
$url = $_GET['url'];
$this->assign('url',$url);
$this->assign('title','Login');
$this->display('user/reg_new.html');
}
|
|
protected function checkLogin() { |
if (not logged in){
$thisurl = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];//Current URL
$thisurl = urlencode($thisurl);//It should be noted here that the obtained url needs to be transcoded, otherwise it will be difficult to pass the URL later
redirect("http://".$_SERVER["HTTP_HOST"]."/cityosweb/default.php/Index/login?url=".$thisurl);
}
}
Then call this method on the page that requires login to ask questions:
The code is as follows
|
Copy code
$this->checkLogin();
This will jump to the login page if you are not logged in. And bring the URL of your previous page:
The code is as follows
|
Copy code
|
public function login() {
$url = $_GET['url'];
$this->assign('url',$url);
$this->assign('title','Login');
$this->display('user/reg_new.html');
}
Obtain the url from the template and submit it to the php backend. After logging in, jump to this url and it's done.
http://www.bkjia.com/PHPjc/631554.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631554.htmlTechArticleOn many websites, users first visit a page to log in, but are not logged in at the time and then log in, waiting for the user to log in successfully. I will definitely want to return to the page I visited last time, so I will...
|
|
|
|