cURL and $_SESSION [message #180166] |
Sun, 20 January 2013 17:17 |
bill
Messages: 310 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
I am invoking a script via cURL, with POST variables. Seems to
work fine, but...
On the first invocation I set a session variable, when I return
to the same script via cURL from the same computer (with a
different command) the session array is empty.
I verified that I am setting the session variable correctly.
What is special about using Session when invoking a script via cURL
-bill
|
|
|
Re: cURL and $_SESSION [message #180167 is a reply to message #180166] |
Sun, 20 January 2013 17:22 |
bill
Messages: 310 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
On 1/20/2013 12:17 PM, bill wrote:
> I am invoking a script via cURL, with POST variables. Seems to
> work fine, but...
>
> On the first invocation I set a session variable, when I return
> to the same script via cURL from the same computer (with a
> different command) the session array is empty.
>
> I verified that I am setting the session variable correctly.
>
> What is special about using Session when invoking a script via cURL
>
> -bill
yes, I do session_start (); as the first executable line in the
script.
-bill
|
|
|
Re: cURL and $_SESSION [message #180168 is a reply to message #180166] |
Sun, 20 January 2013 17:25 |
bill
Messages: 310 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
On 1/20/2013 12:17 PM, bill wrote:
> I am invoking a script via cURL, with POST variables. Seems to
> work fine, but...
>
> On the first invocation I set a session variable, when I return
> to the same script via cURL from the same computer (with a
> different command) the session array is empty.
>
> I verified that I am setting the session variable correctly.
>
> What is special about using Session when invoking a script via cURL
>
> -bill
I have other scripts on that server that use $_SESSION and are
invoked from the web - Session works just fine.
-bill
|
|
|
Re: cURL and $_SESSION [message #180169 is a reply to message #180167] |
Sun, 20 January 2013 17:30 |
Richard Yates
Messages: 86 Registered: September 2013
Karma: 0
|
Member |
|
|
On Sun, 20 Jan 2013 12:22:25 -0500, bill <william(at)TechServSys(dot)com>
wrote:
> On 1/20/2013 12:17 PM, bill wrote:
>> I am invoking a script via cURL, with POST variables. Seems to
>> work fine, but...
>>
>> On the first invocation I set a session variable, when I return
>> to the same script via cURL from the same computer (with a
>> different command) the session array is empty.
>>
>> I verified that I am setting the session variable correctly.
>>
>> What is special about using Session when invoking a script via cURL
>>
>> -bill
>
> yes, I do session_start (); as the first executable line in the
> script.
>
> -bill
This looks like the solution:
http://www.smooka.com/blog/2009/07/24/maintaining-php-session-when-using-cu rl/
|
|
|
Re: cURL and $_SESSION [message #180170 is a reply to message #180169] |
Sun, 20 January 2013 18:53 |
bill
Messages: 310 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
On 1/20/2013 12:30 PM, Richard Yates wrote:
> On Sun, 20 Jan 2013 12:22:25 -0500, bill <william(at)TechServSys(dot)com>
> wrote:
>
>> On 1/20/2013 12:17 PM, bill wrote:
>>> I am invoking a script via cURL, with POST variables. Seems to
>>> work fine, but...
>>>
>>> On the first invocation I set a session variable, when I return
>>> to the same script via cURL from the same computer (with a
>>> different command) the session array is empty.
>>>
>>> I verified that I am setting the session variable correctly.
>>>
>>> What is special about using Session when invoking a script via cURL
>>>
>>> -bill
>>
>> yes, I do session_start (); as the first executable line in the
>> script.
>>
>> -bill
>
> This looks like the solution:
>
> http://www.smooka.com/blog/2009/07/24/maintaining-php-session-when-using-cu rl/
>
That did not do the job, but gave me a hint.
I fixed the problem by adding:
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
so that curl would know where to save the SESSION Cookie and
where to find it for the next script.
-bill
|
|
|