Welcome Guest, Not a member yet? Register   Sign In
Another session and controller redirect problem.
#1

[eluser]bluepicaso[/eluser]
hello,
i know that there are loads of posts and google searches for the same, but i am here after a few days of research.
The problem is that i lose session while redirecting the contoller. But everything was working a week ago. Also important to note the problem is only on localhost not server (application is still on test more for client)
The Process of Login
the username and password are sent to controller

Code:
baseurl = '/careerguiders/';
dataString = 'user='+user.value+'&pwd;='+pwd.value;
    jQuery.ajax({
      type: "POST",
      url: baseurl+"user/login",//-- contoller
      cache: false,
      data: dataString,
      error: function()
      {
        alert('error try again!!'); clearConsole();
      },
      success: function(html)
      {
        if(html>0)
        {
          jQuery('#logAlert').fadeOut();
          jQuery('#logAlert').text('Logging you in please wait');
          jQuery('#logAlert').fadeIn();
          [removed] = baseurl+'user';// ---> redirect to controller index function
        }
        if(html == 0)
        {
          jQuery('#logAlert').fadeOut();
          jQuery('#logAlert').text('Incorrect login details... Please try again');
          jQuery('#logAlert').fadeIn();
        }
        else
        {

        }
        clearConsole();
      }
    });
the "user" contoller and login function

Code:
/*******************************
   * function login
   * @param form
   * function to login user
   *******************************/
  function login() {
    $this->load->library('session');
    $user = $this->input->post('user');
    $pwd = md5($this->input->post('pwd'));
    $cnt = $this->db->count_all("loginDetails where username = '$user' and password ='$pwd' and active = 1");
    if($cnt>0)
    {
      $userdata = @$this->get->userLogin($user, $pwd);
      $this->set->setUserLoginLog($userdata[0]['logId'], real_ip(), date('Y-m-d'));
      //$personalData = $this->get->getUserDataById($userdata[0]['userId']);
      $userSesison = array(
        'userLogdIn'=>true,
        'userData'=>$userdata
      );
      $this->session->set_userData('userSession', $userSesison);//- session is set
      echo 1;
    }
    else
    {
      echo 0;
    }
    //$this->output->enable_profiler(); // when enabled confirms that sessioin is set with proper data
  }

The "User" contoller's index function
Code:
/*******************************
   * function index
   * @param
   * function for user home
   *******************************/
  
  function index() {
    $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
    $this->output->set_header("Pragma: no-cache");
    //$this->output->enable_profiler();// does not shows the session previously shown by login function
    $usersession = $this->session->userdata('userSession');
    if($usersession['userLogdIn'] == true)// checking session  but fails
    {
      $data['userSession'] = $usersession;
      $data['userDetails'] = $this->get->getUserDataById($usersession['userData'][0]['userId']);
      $data['streams'] = @$this->get->getAllStreams();
      $data['levels'] = @$this->get->getLevels(1);
      $data['content'] = 'userHome';
      $this->load->view('includes/template', $data);
    }
    else
    {
      header("location:".base_url());
    }

  }

session library is loaded in autoload.
i can see the session cookie being set after execution of login function.
another point to note that, there is a new session id everytime (as seen via profiler) int login and index function.

I am really upset, another project that i work on localhost works fine use similar ajax and redirections.

Please help







Theme © iAndrew 2016 - Forum software by © MyBB