1
I have this class with the following methods :
 public function __construct($url,$followlocation = true,$timeOut = 30,$maxRedirecs = 4,$binaryTransfer = false,$includeHeader = false,$noBody = false) 
 { 
    //setando valores nas variáveis  
     $this->_url = $url; 
     $this->_followlocation = $followlocation; 
     $this->_timeout = $timeOut; 
     $this->_maxRedirects = $maxRedirecs; 
     $this->_noBody = $noBody; 
     $this->_includeHeader = $includeHeader; 
     $this->_binaryTransfer = $binaryTransfer; 
     $this->_cookieFileLocation = dirname(__FILE__).'/cookie.txt'; 
 } 
public function buildCurl($url = 'nul') 
{ 
    if($url != 'nul'){ 
      $this->_url = $url; 
    } 
     $s = curl_init(); 
     curl_setopt($s,CURLOPT_URL,$this->_url); 
     curl_setopt($s,CURLOPT_HTTPHEADER,array('Expect:')); 
     curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout); 
     curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects); 
     curl_setopt($s,CURLOPT_RETURNTRANSFER,true); 
     curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation); 
     curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation); 
     curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation); 
     if($this->authentication == 1){ 
       curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass); 
     } 
     if($this->_post) 
     { 
         curl_setopt($s,CURLOPT_POST,true); 
         curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields); 
     } 
     if($this->_includeHeader) 
     { 
           curl_setopt($s,CURLOPT_HEADER,true); 
     } 
     if($this->_noBody) 
     { 
         curl_setopt($s,CURLOPT_NOBODY,true); 
     } 
     /* 
     if($this->_binary) 
     { 
         curl_setopt($s,CURLOPT_BINARYTRANSFER,true); 
     } 
     */ 
     curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent); 
     curl_setopt($s,CURLOPT_REFERER,$this->_referer); 
     $this->_webpage = curl_exec($s); 
     $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE); 
     curl_close($s); 
     } 
     public function getResponse($url)
     { 
       $this->buildCurl($url);
       return $this->_webpage; 
     } 
and here the method call in another file in my controller .
     public function cURL($id)
     {
       $_url = "https://receitacpf.cf/api/cpf/$id";
       $curl = new Curl($_url);
       return $curl->getResponse($_url);
     }
I wonder why is not giving any more error also is not bringing anything , to break the head in this
You’re just returning somewhere to sponse, and not printing it. Run a
print_r()orvar_dump()orvar_export()return this function and show us what appears.– Godfrey the King
gave a var_dump() and at least already return something like this : string(3309) " "
– Pedro Amorim
If you access this API and place your CPF
https://receitacpf.cf/api/cpf/you will see that the total of characters you will get on the page is 3309.– Godfrey the King
Run the test at http://onlinecurl.com/. Enter the api URL + a Cpf.
– Godfrey the King
Explaining what’s happening... While executing
echoorvar_dump()you will see everything blank, however, right-click anywhere on the blank screen and go toExibir o código fonte da página. Then you will see that the result of yourcURLis there.– Godfrey the King
thanks for the help , more as I would have to do to bring for example result otherwise ?
– Pedro Amorim