HTTP Tips & Tutorials PHP Tips & Tutorials

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('');
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 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.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Shoot me a message.