Backup pfSense via PHP + cURL



  • I'm trying to hold up the pfSense through php + curl lib. But it reports the following error:

    CSRF check failed. Your form session may have expired, or you may not have cookies enabled.

    Code:

    $camposPost = array (  'usernamefld' => 'admin', 'passwordfld' => 'password');

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'https://pfsense');
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_POST, true );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldPost);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:  "));

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    curl_exec($ch);

    curl_close($ch);

    ?>


Log in to reply