How to update cURL request when calling script

0

I have a system, which opens an external site inside it, but I have a small hitch; every time the page is accessed for the first time, the data obtained from the external page are not updated, they are saved in cache and stays forever, wanted to update this entire data made the page call the script responsible for opening the external page.

I pass the data by Javascript to the file PHP , the javascript takes the url of the news on the site, and sends through the GET parameter to the script PHP , which performs the opening of the site making use of the cURL library. The Script PHP looks like this:

if(preg_match("#Politica#",$_GET['u'])){
    $ir = $_GET['u'];
    ob_start();
    $cot = new ExibirPolitica();
    $cot -> setUrlc($ir);
    $cot -> printCot();
    $conteudo = ob_get_contents();
    ob_end_clean();
    echo $conteudo;

}

The class ExibirPolitica(); contains only one cURL as follows:

        $header = "X-Forwarded-For: {$_SERVER['REMOTE_ADDR']}";
        $h2 = "Cache-Control: no-cache";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_REFERER, "https://noticiando.com");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array($header,$h2));
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
        $html = curl_exec($ch);

As you can see, I tried to use ob_end_clean(); and print the content below to see if it was updated, I also tried " no-cache" no cURL , also unsuccessful!"

Is there any way to "force" the update of content obtained by cURL ?

    
asked by anonymous 11.05.2015 / 08:33

1 answer

1

I do not know how your URL is formatted, but I think you have some variables in it. So I have two suggestions.

// Em ambos casos, você precisará da variável com valor pseudo-exclusivo
// A chance do valor dessa variável se repetir é praticamente nula
// Foi dado o nome de "_u" mas pode ter qualquer outro nome
$u = '_u=' . microtime(true) . ':' . rand();

Segment 1: Continue using the GET method and append the variable to the end of the URL:

$u = ((strpos($url, '?') === false) ? '?' : '&') . $u;
curl_setopt($ch, CURLOPT_URL, $url . $u);

Segment 2: Use the POST method and send the variable via this:

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $u);

I think these two suggestions will work because they both produce a virtually unique request.

    
11.05.2015 / 15:44