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.
Related Posts
- PHP cURL: Making POST Request to URL
- Pretend your scraper script as a browser when scraping in PHP
- PHP: setcookie() with HttpOnly Option to Reduce XSS (Cross Site Scripting) Attacks by Preventing JavaScript from Reading Cookies
- PHP: How to detect / get the real client IP address of website visitors?
- Apache, PHP: Get Client Browser HTTP Request Headers Information
