developarvin
developarvin

Reputation: 5087

Is there way to retain session when curling into a url?

Let's say I have a domain foo.com and it has a page called foo.com/bar.php

In one of the functions in the site, I try accessing foo.com/bar.php via cURL.

However, some stuff in foo.com/bar.php is dependent on the current session.

Hence, I want to retain the current session of the calling method into the cURL method.

Is there a way to do this?

Upvotes: 1

Views: 65

Answers (1)

Bram Hammer
Bram Hammer

Reputation: 388

You have to setup some additional curl options:

curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

With above settings the cookies will be stored in cookie.txt :)

Upvotes: 1

Related Questions