0

I know I am getting the data from the xml that I retrieved from a URL, I tried to echo it and it's working perfectly fine. However, when I try to put that data to a session userdata, it doesn't add to the session. below is my code:

    $username = $this->input->post("user");
    $password = $this->input->post("pass");
    $ip = $this->input->ip_address();

    if(!$this->input->valid_ip($ip)){
        $this->session->set_flashdata('failed','Login Failed! Error: Invalid IP');
        redirect("lobby");
    }

    $url = "http://www.betclip.net/betclipapi/methods.asp?OperatorId=someID&key=somekey&action=login&username=".$username."&password=".$password."&ip=".$ip." ";

    $opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
    $context = stream_context_create($opts);
    $user_log = file_get_contents($url,false,$context);
    $user_list  = simplexml_load_string($user_log);

    $code = $user_list->errorCode;

    //$check_result = $this->Login_m->get_user($username, $password);
    if($code == 0)
    {
        $data = array(
                        'login' => TRUE, 
                        'id' => $user_list->accountid,
                        'username' => $user_list->username, 
                        'symbol' => $user_list->symbol, 
                        'balance' => $user_list->balance,
                        'ip' => $user_list->ip
                    );
        $this->session->set_userdata($data);
        $this->session->set_flashdata('welcome','Welcome ' . $this->session->userdata('Username') . '!');
        redirect('lobby');
    }
    else
    {
        $this->session->set_flashdata('failed','Login Failed! Error: ' . $user_list->description . '');
        redirect('lobby');
    }

What am I missing? I use files as my sess_driver:

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = BASEPATH . 'cache/sessions/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
TheTruth
  • 25
  • 8

1 Answers1

0

Okay, so I have researched further. What I found is that you have to convert the retrieved data from XML into a string

$data = array(
        'login' => TRUE, 
        'id' => (string)$user_list->accountid,
        'username' => (string)$user_list->username, 
        'symbol' => (string)$user_list->symbol, 
        'balance' => (string)$user_list->balance,
        'ip' => (string)$user_list->ip
);

I hope this can help anyone who has the same problem.

Credits to this thread: here

Community
  • 1
  • 1
TheTruth
  • 25
  • 8