Curl return 0 but doesn't not work

258 Views Asked by At

I'm trying to call an url in curl to launch a backup, which is working perfectly in my browser. Curl return 0 so there seems to be no error, however it doesn't do the backup.

Here is my code:

public function runBackup(){

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'http://localhost/bnc_update/kybackup/backup-in-background');
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Requested-With: XMLHTTPRequest','User-Agent: KaliMessenger'));

    curl_exec($ch);

    if( ! $result = curl_exec($ch)) 
    { 
        trigger_error(curl_error($ch)); 
        echo '<pre>';
        print_r(curl_getinfo($ch));
        echo '</pre>';
        echo 'Erreur Curl : ' . curl_errno($ch) . '<br/>';

    }  
    echo 'Result: <br/>';
    var_dump($result);

    curl_close($ch);
    exit();
}

Which output:

Array
(
[url] => http://localhost/bnc_update/kybackup/backup-in-background
[content_type] => text/html; charset=UTF-8
[http_code] => 301
[header_size] => 656
[request_size] => 149
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.162641
[namelookup_time] => 6.9E-5
[connect_time] => 0.000186
[pretransfer_time] => 0.000214
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.162623
[redirect_time] => 0
[redirect_url] => http://localhost/bnc_update/sign-in?back-uri=kybackup%252Fbackup-in-background
[primary_ip] => ::1
[certinfo] => Array
    (
    )

[primary_port] => 80
[local_ip] => ::1
[local_port] => 56883
)

Erreur Curl : 0
Result:
string(0) ""

I see there is a redirect_url, could it be the problem? I'm already logged in in the browser though, do I need to perform another request to login again?

0

There are 0 best solutions below