I'm using curl to login to a website:
$credentials = [
'user' => 'username',
'password' => 'passowrd',
];
curl_setopt($ch, CURLOPT_URL, 'https://shop.com/login.php');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($credentials));
$response = curl_exec($ch);
It works to log in but once i'm logged in i need to go trough a few urls and crawl some data(which is available only after log in):
$products = ['1', '2', '3'];
foreach ($products as $id) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://shop.com/product.php?id=' . $id);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
//do something with that response
curl_close($ch);
}
Is there a way to maintain that session started in the first curl request so i can use it in the foreach loop - so i can crawl my data?
Thank you!