Can someone explain to me why I am not capable of forcing a new ExpressionEngine session to be generated for a specific user? I've been following this link: https://stackoverflow.com/questions/13073134/what-is-the-best-way-to-log-a-user-in-programatically-in-expressionengine
What I am trying to do is to temporarily create an EE session, and then to create a channel entry for that logged in user. I can then destroy the session. However, my PHP script seems to fall down when it sees $this->EE. Is there something in particular I need to do to initiate the EE variable to begin with?
See my code below. Do I need to place this code in a template or something else?
// Get the member's id (the member must have permissions to post entries)
$log_in_id = 23; // [email protected] - member id //
// Create session
echo 'before new session | ';
$this->EE->session->create_new_session($log_in_id);
//$this->EE->session->create_new_session(23, TRUE);
echo 'after new session | ';
print_r($this->EE->session);
$this->EE->load->library('api');
$this->EE->api->instantiate('channel_entries');
$data = array(
'channel_name' => 'members', //[Required]
'title' => $tmp_firstname.' '.$tmp_lastname, //[Required]
'author_id' => $memberID,
//'entry_id' => 0,
'field_id_37' => $memberID,
'field_id_38' => $tmp_firstname,
'field_id_39' => $tmp_lastname,
'field_id_70' => $tmp_company,
'field_id_71' => $tmp_ref,
'field_id_73' => $tmp_qty,
'field_id_74' => $tmp_remainder,
'field_id_72' => $tmp_owner
);
print_r($data);
$this->EE->api_channel_fields->setup_entry_settings(1, $data);
if ($this->EE->api_channel_entries->submit_new_entry(1, $data) === FALSE){ echo '[ERROR]'; }
else{ echo 'SUCCESS'; $this->EE->session->destroy(); }
Any info would be appreciated!