PHP cURL: Fetching URL and Sending Request with Cookies

One of the things the remote web server inspects is the client cookie to know about the requester. If you need cURL to simulate a user browser that sends cookie information to the web server, you need the following options:

$c = curl_init('http://www.example.com/needs-cookies.php');
curl_setopt ($c, CURLOPT_COOKIE, 'user=ellen; activity=swimming');
curl_setopt ($c, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec ($c);
curl_close ($c);

So, the HTTP request cURL sends out to www.example.com will take the cookie data with it, thus the remote script needs-cookies.php knows the information and determines that the request is sent from the user ellen’s web browser.

Scroll to Top