KyranRana / cloudflare-bypass

A new and improved PHP library which bypasses the Cloudflare IUAM page using cURL
MIT License
274 stars 98 forks source link

Integrate v2 into my class #60

Closed nitemare closed 6 years ago

nitemare commented 6 years ago

I'm trying to switch from v1 to v2, as v1 has stopped working, and v2 seems to work when i test it on its own. but when i attempt to integrate it in to my class, i'm getting an error about "Use". Admittedly i'm not familiar with Use or how to fix it. The error is:

Parse error: syntax error, unexpected 'use' (T_USE) in .....

here is an example of my code: `

class Source{

public $dbase = NULL;
public $be = NULL;
public $log = NULL;

public function getSite($url, $dump = false){

    require_once './libraries/autoload.php';    
    use CloudflareBypass\RequestMethod\CFCurl;

    $curl_cf_wrapper = new CFCurl(array(
        'cache'         => true,   // Caching now enabled by default; stores clearance tokens in Cache folder
        'max_retries'   => 5       // Max attempts to try and get CF clearance
    ));

    // Get Example: 1
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36');
    $site = $curl_cf_wrapper->exec($ch); // Done! NOTE: HEAD requests not supported!
    curl_close($ch);

    return $site;
}

} `

railken commented 6 years ago

http://php.net/manual/en/language.namespaces.importing.php

"The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations. This is because the importing is done at compile time and not runtime, so it cannot be block scoped. "

I hope this will help

nitemare commented 6 years ago

it did, thanks :)