lantosbro / cloudflare-bypass
一个帮助绕过 Cloudflare UAM 页面的库。
dev-master
2023-10-17 19:14 UTC
Requires
- php: ^7.2
- ext-bcmath: *
- ext-curl: *
- ext-json: *
- lantosbro/simple-javascript-compilation: dev-main
Requires (Dev)
- phpunit/phpunit: ^6.5.5
This package is auto-updated.
Last update: 2024-09-17 20:58:26 UTC
README
不幸的是,Cloudflare 正在实施的新更改将无法在 PHP 中实施或维护。因此,我不得不说这个项目将归档。Cloudflare 玩得很好。
Cloudflare Bypass
一个使用 cURL 绕过 Cloudflare IUAM 页面的新改进的 PHP 库。
安装
使用 composer
composer require kyranrana/cloudflare-bypass
使用 cURL 的用法
像平常一样使用 cURL,但不是使用 curl_exec
来执行请求,我们提供了一个名为 CFCurlImpl
的类。 CFCurlImpl
提供了一个 exec
方法,它接受你的 cURL 处理并执行它 - 如果出现 IUAM 页面,将处理该页面。
方法定义
CFCurlImpl->exec(resource $curlHandle, UAMOptions $uamOptions)
示例
<?php use CloudflareBypass\CFCurlImpl; use CloudflareBypass\Model\UAMOptions; /* * Prerequisites * * Set the following request headers: * * - Upgrade-Insecure-Requests * - User-Agent * - Accept * - Accept-Language * * Set the following options: * * - CURLINFO_HEADER_OUT true * - CURLOPT_VERBOSE false * */ $url = "https://predb.me/?search=720p"; $ch = curl_init($url); // Want to cache clearance cookies ? //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "Accept-Language: en-US,en;q=0.9" )); $cfCurl = new CFCurlImpl(); $cfOptions = new UAMOptions(); $cfOptions->setVerbose(true); // $cfOptions->setDelay(5); try { $page = $cfCurl->exec($ch, $cfOptions); // Want to get clearance cookies ? //$cookies = curl_getinfo($ch, CURLINFO_COOKIELIST); } catch (ErrorException $ex) { echo "Unknown error -> " . $ex->getMessage(); }