mediashare/cloudflare-bypass

一个帮助绕过Cloudflare UAM页面的库。

3.4.0 2020-03-24 20:16 UTC

This package is auto-updated.

Last update: 2024-09-16 23:23:08 UTC


README

遗憾的是,Cloudflare实施的新更改在PHP中无法实现和维护。因此,我很遗憾地说,这个项目将要归档。Cloudflare玩得很聪明。

Cloudflare Bypass

CI

一个新改进的PHP库,使用cURL绕过Cloudflare IUAM页面。

安装

使用composer

composer require kyranrana/cloudflare-bypass

使用cURL的方式

像平时一样使用cURL,但我们提供了一个名为CFCurlImpl的类来执行请求,而不是使用curl_exec来执行请求。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();
}