Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Session userdata is being lost
#21

[eluser]TheFuzzy0ne[/eluser]
OK - After mangling your code enough to get it working without the database, everything seems to be working for me.

I'd suggest you override the profiler and enable it to see what's happening with the session, since by default, the profiler doesn't show anything to do with sessions:


Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Profiler extends CI_Profiler {
    /**
     * Adds session data to the profiler
     * Adds a table row for each item of session data with the key and value
     * Shows both CI session data and custom session data
     */
    function _compile_session() {    
        $output  = "\n\n";
        $output .= '<fieldset style="border:1px solid #009999;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
        $output .= "\n";
        $output .= '<legend style="color:#009999;">&nbsp;&nbsp;'.'SESSION DATA'.'&nbsp;&nbsp;</legend>';
        $output .= "\n";
            
        if (!is_object($this->CI->session)) {
            $output .= "<div style='color:#009999;font-weight:normal;padding:4px 0 4px 0'>".'No SESSION data exists'."</div>";
        } else {
            $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
            
            $sess = get_object_vars($this->CI->session);
    
            foreach ($sess['userdata'] as $key => $val) {
                if ( ! is_numeric($key)) {
                    $key = "'".$key."'";
                }
        
                $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>$_SESSION[".$key."]&nbsp;&nbsp; </td><td width='50%' style='color:#009999;font-weight:normal;background-color:#ddd;'>";
                if (is_array($val)) {
                    $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>";
                } else {
                    $output .= htmlspecialchars(stripslashes($val));
                }
                $output .= "</td></tr>\n";
            }
        
            $output .= "</table>\n";
        }
        $output .= "</fieldset>";

        return $output;    
    }
  
    function run() {
        $output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>";

        $output .= $this->_compile_uri_string();
        $output .= $this->_compile_controller_info();
        $output .= $this->_compile_memory_usage();
        $output .= $this->_compile_benchmarks();
        $output .= $this->_compile_get();
        $output .= $this->_compile_post();
        $output .= $this->_compile_queries();
        $output .= $this->_compile_session();

        $output .= '</div>';

        return $output;
    }
}

You can enable this by adding:
Code:
$this->output->enable_profiler(TRUE);

to your controller constructor, which will enable the profiler for all methods in that controller.
#22

[eluser]zbrox[/eluser]
Code:
$_SESSION['session_id']       9c30684ddb0136ba409f8c8d384675ed
$_SESSION['ip_address']       127.0.0.1
$_SESSION['user_agent']       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1
$_SESSION['last_activity']       1246340375

This is the only output for the sessions that the profiler outputs. Also there is the query to the database selecting the session and it's executed fine. I ran it manually.
The user_data field in the database is a CLOB. I don't think it has anything to do with this but I'm starting to make wild guesses...
#23

[eluser]zbrox[/eluser]
I enabled CI logging and put a log_message before every sess_destroy call in the Session class. None of the messages came up there. I'm starting to think I'm doing something in a very wrong way and it's in front of my eyes, but I just can't seem to find it.
#24

[eluser]zbrox[/eluser]
I finally solved this. So Oracle is the culprit here. First it was my error that the user_data field is CLOB but not varchar. You have to use the load method on the CLOB field in PHP to use it as a string. It's kinda messy but I put that in the Session class. Second, the user_data field is in small caps while the result array returns the fields in all uppercase. Which reminds me that I had to make another change to the OCI8 active record driver. It was enclosing the field names in double quotes (") which broke the queries to the Oracle database.
#25

[eluser]TheFuzzy0ne[/eluser]
I'm glad you figured it out. Oracle certainly sounds like more trouble than it's worth. I've never had these kind of problems with MySQL. Smile
#26

[eluser]jedd[/eluser]
Oracle is to SQL what Solaris is to unix.

(I've got dozens of these, btw.)
#27

[eluser]zbrox[/eluser]
In this case it was not up to me to decide what database to be used. So I'm dealing with it Smile




Theme © iAndrew 2016 - Forum software by © MyBB