doujia2090 2014-07-18 11:43
浏览 52
已采纳

使用codeigniter重定向到上一页

I have a login form with URL

index.php/Login

after login it shows me home page with same URl because i have called the view in index function of login controller. Now problem is when i click change password button it redirects to

index.php/Login/change_password

now if i called site_url('Login') from change_password, it redirects me to login page but not back to user home page.

my Login controller code id below

  public function index(){

       $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->load->database();

        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required');

        if($this->form_validation->run() == FALSE){

            $this->load->view('login');

        }
        else
        {

            $this->load->model('user_data');
            $email = $this->input->post('email');
            $data['info'] = $this->user_data->login_user($email,  $this->input->post('password'));
            $this->load->library('session');
            $user = $data['info'];
            $this->session->set_userdata($user);
            $this->load->view('employee_main');

        }

Any help will be greatly appricated.

  • 写回答

2条回答 默认 最新

  • drhgzx4727 2014-07-18 11:58
    关注

    try to use session

    first change:-

    $this->session->set_userdata($user);
    

    to

    $this->session->set_userdata('myuser_session', $user); //giving a name to detect
    

    Then check session is exist

    public function index(){
      $this->load->library('session');
      if($this->session->userdata('myuser_session')) {
        redirect(site_url());
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路