duanbi9202 2013-08-07 17:07
浏览 52

会话管理用于Codeigniter中的重定向

I want to manage page redirection in codeigniter, I have two controllers:

  1. Logggedin
  2. login

When user try to access login page while he is logged in, he is redirected to Loggedin controller

function __construct()
{
    parent::__construct();
    $u = $this->session->userdata('username');

    if(! isset($u))
    {
        redirect('loggedin');
    }
}

And when he tries to access Loggedin controller while he is not logged in, he should be redirected to login controller

function __construct()
{
    parent::__construct();
    $u = $this->session->userdata('username');

    if(isset($u))
    {
        redirect('login');
    }
}

But when I press logout button, it has to redirect to Login controller, but he still remains on Logggedin controller.

function logout()
{
    $this->session->sess_destroy();
    redirect('login');
} 

What could be the problem in code?

  • 写回答

2条回答 默认 最新

  • dongrou5254 2013-08-07 17:11
    关注

    In order to use codeigniter redirect function you must include the codeigniter url helper file, in which this function is actually written.

    So, Load the codeigniter url helper file in your constructor

    $this->load->helper('url');
    

    and try by putting a '/' in front of the uri segment

    redirect('/login');
    

    Your redirect function is not working, as on logout, your session is destroyed, but the redirect is not taking place.

    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思