dongzhuo3059 2012-04-18 21:36
浏览 29
已采纳

CodeIgniter会话变量未传递

I am using native PHP sessions ($_SESSION) with CodeIgniter framework.

I have a "Login" controller loads view where user enters login and password. After the user submits the login form, the "Login" controllers authenticate() method is called. If everything is alright i add some data to $_SESSION array, then i redirect user to "Organisation" controllers myOrganisation() method. I'm calling session_start() in Login/login() , Login/authenticate() and Organisation/myOrganisation() methods, but still the session is not passed, because in myOrganisation() method the session is new.

I tested my cookies functionality with creating 2 test php pages, where i just echo session id. It works perfectly. Maybe i am not putting session_start() in all places it needs to be? (i put them in all controllers methods).

Login Controller:

class Login extends CI_Controller {
public function index() {
        session_start();
        $this->load->view("Login/index", $data);

    public function authenticate() {
                    session_start();
                    $_SESSION['login'] = $login; //  everything is alright, redirect
        header("location: ".base_url()."Organisations/MyOrganisation");

Organisation controller:

public function MyOrganisation() {
    session_start(); // here session is a new one, not passed
    if(isset($_SESSION['login'])) {
  • 写回答

2条回答 默认 最新

  • dtfpznrbn503027700 2012-04-21 20:26
    关注

    I don't know what was wrong with the session_start() placements that i did, but the one thing that solved the problem was to place it in index.php in main folder

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现