无法在第二个函数中获取会话内容

I am having some issues with sessions.

In the first function queue, I save the session entries I can print this out from this function, so I can see its being set correctly.

In the function remove, I try and save this entries session into a variable and I get the error that entries is an undefined index.

Does anyone have any ideas what I am doing wrong here?

function queue() 
{
    session_start();

    $status = 'Awaiting Moderation';
    $channel = '1';

    // Find all entries in 'Gallery' channel with 'Awaiting Moderation' status
    $this->EE->db->select('entry_id')
                 ->from('exp_channel_titles')
                 ->where('status', $status)
                 ->where('channel_id', $channel);

    $query = $this->EE->db->get();      
    $entries = $query->result_array();

    $entries_count = count($entries);

    // Set count
    $_SESSION['entries_count'] = $entries_count;    

    // If entries found
    if ($entries_count > 0)
    {
        // Flatten entry ids array
        $entriesFlat = array();
        array_walk_recursive($entries, function($a) use (&$entriesFlat) { $entriesFlat[] = $a; });

        $entriesSerial = serialize($entriesFlat);

        // Save in session
        $_SESSION['entries'] = $entriesSerial;
    }

}

function remove()
{
    session_start();

    // Get session data + save into variable
    $entries = $_SESSION['entries'];

}

You can only have one session and it should be at the top of your file.

Since your using codeigniter why not use codeigniter session and then autoload library and then you can do code like below.

$this->session->set_userdata('entries_count', $entries_count);

To Get Data

$this->session->userdata('entries_count');

And

$this->session->set_userdata('entries', $entriesSerial);

To Get Data

$this->session->userdata('entries');

// Example

if ($this->session->userdata('entries') > 0)
{

User Guide

CI2 http://www.codeigniter.com/userguide2/libraries/sessions.html

CI3: http://www.codeigniter.com/user_guide/libraries/sessions.html

http://www.codeigniter.com/docs

1st of all, there's not need to declare 'session' again at 'remove()' function..

2ndly to set session contents you have to write :

$this->session->set_userdata('entries_count', $entries_count);  

Instead of

$_SESSION['entries'] = $entriesSerial; 

Save it in session

To get session contents you've to write:

$entries_count = $this->session->userdata('entries_count'); 

Get session data + save into variable

Then you can write the condition like:

if ($entries_count > 0) {

}

Similarly, you've to write

$this->session->set_userdata('entries', $entriesSerial); 

To save in session instead of

$_SESSION['entries'] = $entriesSerial;

And

$entries = $this->session->userdata('entries'); 

To Get session data + save into variable