CodeIgniter Forums
Sessions + cURL = problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Sessions + cURL = problem (/thread-36905.html)



Sessions + cURL = problem - El Forum - 12-19-2010

[eluser]a77icu5[/eluser]
why when I run api.server.com/users/createsession from api.server.com my sessions are created without problems in api subdomain, but if I run api.server.com/users/createsession from a curl request through other domain these are ignored and not created?

I need that with my curl request in api.server.com, create and save sessions in the same subdomain can someone help?


Sessions + cURL = problem - El Forum - 12-20-2010

[eluser]a77icu5[/eluser]
Example
create_sess.php
Code:
session_start();
$_SESSION['my_sess'] = 'some session value';

the...you can run
Code:
http://localhost/create_sess.php

And that's great !...the session it's ok, but try doing this

Code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/create_sess.php');
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$content = curl_exec($ch);
curl_close($ch);

then...we got problems, the session is not set, why ?


Sessions + cURL = problem - El Forum - 12-20-2010

[eluser]a77icu5[/eluser]
resolved


Sessions + cURL = problem - El Forum - 03-08-2011

[eluser]Unknown[/eluser]
Hey,

I kind of have the same problem, how did you managed to do it ?
thanks


Sessions + cURL = problem - El Forum - 03-08-2011

[eluser]a77icu5[/eluser]
Hi Abderrahmane, curl_exec($ch) create the sessions in the server, you can test returning the session value to see the result but curl_close($ch) "clean" everything in the server, then the sessions are destroyed, there's no way to store session with curl...


Sessions + cURL = problem - El Forum - 05-12-2012

[eluser]The Questioner[/eluser]
I've had this same problem and also wanted to know how you resolved it?

I have a script that sits outside CI and sends POST data to a specific CI controller using CURL.

The problem I’m having is that when the POST data is passed into my controller by CURL, all CI session variables are empty within the controller - but only during the CURL post. My controller relies on the cart session variable as well as other session variables (which were populated prior to the CURL call).

If I open another tab on my browser and call the same controller through via a URL, the session variables are back again.

How can I keep the session variables alive when the CURL POST is made?