Exemple #1
1
<?php

ini_set('display_errors', 1);
require_once 'libraries/httpProxyClass.php';
require_once 'libraries/cloudflareClass.php';
$httpProxy = new httpProxy();
$httpProxyUA = 'proxyFactory';
$requestLink = 'https://coinkite.com/';
$requestPage = json_decode($httpProxy->performRequest($requestLink));
// if page is protected by cloudflare
if ($requestPage->status->http_code == 503) {
    // Make this the same user agent you use for other cURL requests in your app
    cloudflare::useUserAgent($httpProxyUA);
    // attempt to get clearance cookie
    if ($clearanceCookie = cloudflare::bypass($requestLink)) {
        // use clearance cookie to bypass page
        $requestPage = $httpProxy->performRequest($requestLink, 'GET', null, array('cookies' => $clearanceCookie));
        // return real page content for site
        $requestPage = json_decode($requestPage);
        echo $requestPage->content;
    } else {
        // could not fetch clearance cookie
        echo 'Could not fetch CloudFlare clearance cookie (most likely due to excessive requests)';
    }
}
 /**
  * Assigns given user agent string to bypass requests (Required)
  * Note: Make this the same user agent you use with your cURL requests
  *
  * @param string $userAgent  User Agent String 
  *
  * @return void  Sets user agent for request
  */
 public static function useUserAgent($userAgent)
 {
     self::$userAgent = $userAgent;
 }