Is it legal to use PHP scripts to log in to websites and access data without permission?

It is illegal to use PHP scripts to log in to websites and access data without permission. This is considered unauthorized access and violates the Computer Fraud and Abuse Act. To access data from websites, you should always obtain proper authorization and follow the terms of service.

// This code snippet is for educational purposes only and should not be used to access websites without permission.

// Example of how to access data from a website with proper authorization
$ch = curl_init();
$url = "https://example.com/data";
$headers = array(
    'Authorization: Bearer YOUR_ACCESS_TOKEN'
);

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

if($response === false){
    echo 'Error: ' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);