Ajax controller for login - Problem session->set_userdata


I have created an ajax controller (on sessions module) with static data to set the login session for a user. If i go to this controller with browser (link: http: // localhost: 8888 / index.php / sessions / ajax / setsession) works and the session works correctly: the user is logged on invoiceplane.

The AJAX controller code:


$session_data = array(
    'user_type' => '1',
    'user_id' => '1',
    'user_name' => 'Luca',
    'user_email' => 'lucatest@test.it',
    'user_company' => ''

If i try to do this with php (file_get_contents) or php (curl), the system does not work, the sessions are not created and the user is not logged.

I have read the session library and i think there is a block on your code or similar stuff.

Is this the problem? What is the solution?

Please help me to solve.


You can’t use file_get_contents or similar stuff to pass a session to a user.

Why using a controller to set static session data for a user? Makes no sense to me. Maybe you should explain what you want to do so we can help you with your idea… :thinking:


i must call the login controller to able the user’s login with another file php.
So i have a web form and with php i must enable login session into InvoicePlane.
So i have create this ajax controller.

How can i do this?

I do not think that this is possible with the current codebase InvoicePlane offers. You would have to extend the app with both an API that handles external user logins and a session handler that allows external authentications based on methods that would need to be discussed about in regards of security.

ok, but why with browser url invoke works and with curl no?

The session is created and saved on db but i think there is a problem with cookies.

There is a solution?

Because using curl inside a PHP file will make your PHP file become the user, not the browser that opens the PHP file.

This is not a problem with cookies (which are not used anymore). It is not a problem at all because that’s how the architecture works.
InvoicePlane does not support what you want to do yet.

There are other solutions or documentation? In next version of invoice plane there is this functionallity?

No, InvoicePlane is not capable of your feature and will not ge the desired features in the next time. Sorry.

hi, but codeigniter framework has this functionallity.

There is some libraries, plugins or helpers do do this?

InvoicePlane was build with Codeigniter but is not the framework itself. Not possible at the moment. Period.