如何在刷新页面时将用户重定向到其他控制器

时间:2013-11-17 09:11:04

标签: php codeigniter redirect controller

我正在开发codeigniter。我正在实现登录功能,当用户登录时,我称之为控制器

function validate_credentials()
{   
    $this->load->model('membership_model');
    $query = $this->membership_model->validate();

    if($query==1)
    {
        $data = array 
        (
            'username'=>$this->input->post('username'),
            'is_logged_in' => true
        );
        $email=$data['username'];

        $this->session->set_userdata('email_of_user',$email);
        $this->load->model('search_peoplee');
        $data['userid']= $this->search_peoplee->get_userid_from_email($email);
        foreach ($data['userid'] as $row)
            {
                $one=$row->userid;
            }
        $data['result']=$this->membership_model->friend_notify($one);

        $data['count']=$this->search_peoplee->get_friends_count($one);
        $this->load->model('search_peoplee');
        $data['values']= $this->search_peoplee->get_notifications($one);
        $data['count_notify']=$this->search_peoplee->get_notifications_count($one);
        $this->session->set_userdata('lookatit','no');
        $this->load->view('home_screen',$data);
    }
    elseif($query==2)
    {
        $data['main_content']='email_not_found';
        $this->load->view('includes/template',$data);
    }
    else
    {
        $this->error_index();
    }
} 

这会验证凭据并存储会话,此控制器会调用模型“$ this-> membership_model-> validate();”选择值表单视图并检查如果用户存在,问题是当我重新键入它到达登录页面的地址并且在模型读取空值时再次登录。如何避免这种情况。帮助!

1 个答案:

答案 0 :(得分:0)

经过身份验证后,如何设置会话变量。 所以,

$this->session->set_userdata('authenticated',TRUE);

然后在控制器中,首先检查用户是否经过身份验证并进行重定向,否则转到validate_credentials方法??