DEV Community

Emmanuel David
Emmanuel David

Posted on

How to authenticate with cookie and curl to scrape a laravel-built website


$url = 'https://example-built-with-laravel.com/dashboard'
$userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36";

$ch = curl_init();

$ckfile = 'cookies.txt';

curl_setopt_array($ch, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_USERAGENT => $userAgent,
    CURLOPT_COOKIESESSION

Top comments (0)