【问题标题】:How to redirect user to a different controller on refreshing the page如何在刷新页面时将用户重定向到不同的控制器
【发布时间】:2013-11-17 09:11:03
【问题描述】:

我正在开发 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();”它选择值表单视图并检查用户是否存在,问题是当我重新输入地址时,它会将我带到登录页面并在模型读取空值时再次显示登录。如何避免这种情况。救命!!!

【问题讨论】:

    标签: php codeigniter redirect controller


    【解决方案1】:

    认证后,如何设置会话变量。 所以,

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

    然后在controller中,先检查用户是否认证通过并做重定向,否则进入validate_credentials方法??

    【讨论】:

    • 用户在登录后被重定向到该页面,当用户在该页面上时他已经登录,现在如果他刷新我想调用不同的控制器函数
    • 您的意思是使用redirect(),并使用标志来确定何时重定向?
    猜你喜欢
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多