用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1872|回复: 4
收起左侧

[版本 3.x] 后台登录问题,登录会显示两次

[复制链接]
发表于 2016-9-13 12:13:40 | 显示全部楼层 |阅读模式
20CI币
PHP复制代码
class Admin extends CI_Controller {    
        public function __construct()
    {
        parent::__construct();
                $this->load->helper('cookie');
                $this->load->library('session');
                $this->load->model('stu_model');
                $this->load->model('th_model');
                if(!$this->allcklg()){
                        $this->login();
                }
    }
//登录页
        public function login(){
               
                if($this->allcklg()){
                        redirect('admin/index');
                }else{
                        $this->load->helper('captcha');
                        $vals = array(
                        'img_path' => './captcha/',
                        'img_url' => base_url().'captcha/',
                        'word_length'   => 2,
                        'expiration'    => 60,
                        'img_width' => '80'
                        );
                        $data['cap'] = create_captcha($vals);
                        $this->session->capword = $data['cap']['word'];
                        $this->load->view('admin/login',$data);
                }
               
        }
 
//登录通用验证
        public function allcklg(){
                $userid = $this->session->userid;
                if($userid){
                        return  $userid;
                }else{
                        return false;
                }
               
        }
复制代码




如果没有登录,登录页打印了两次,如下:
5555555555.png

请问如何修改,让它只显示一次。

最佳答案

查看完整内容

把__construct()内的 if(!$this->allcklg()){ 改为 if(!$this->allcklg() and $this->uri->segment(2) != 'login'){ 即可
发表于 2016-9-13 12:13:41 | 显示全部楼层
把__construct()内的

if(!$this->allcklg()){

改为

if(!$this->allcklg() and $this->uri->segment(2) != 'login'){

即可
回复

使用道具 举报

发表于 2016-9-13 13:46:37 | 显示全部楼层
問題在這邊

PHP复制代码
 
if(!$this->allcklg()){
    $this->login();
}
 
复制代码


回复

使用道具 举报

发表于 2016-9-13 14:05:43 | 显示全部楼层
登录的 URL 是什么?
回复

使用道具 举报

 楼主| 发表于 2016-9-13 15:13:34 | 显示全部楼层
燃雲 发表于 2016-9-13 14:07
把__construct()内的

if(!$this->allcklg()){

谢谢,这个方法不错。 用这个解决了。
回复

使用道具 举报

本版积分规则