PHP code example of vinodsai-a / safecurl

1. Go to this page and download the library: Download vinodsai-a/safecurl library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vinodsai-a / safecurl example snippets


use fin1te\SafeCurl\SafeCurl;
use fin1te\SafeCurl\Exception;

try {
    $url = 'http://www.google.com';

    $curlHandle = curl_init();

    //Your usual cURL options
    curl_setopt($curlHandle, CURLOPT_USERAGENT, 'Mozilla/5.0 (SafeCurl)');

    //Execute using SafeCurl
    $safeCurl = new SafeCurl($curlHandle);
    $response = $safeCurl->execute($url);
} catch (Exception $e) {
    //URL wasn't safe
}

use fin1te\SafeCurl\SafeCurl;
use fin1te\SafeCurl\Options;

$options = new Options();
$options->addToList('blacklist', 'domain', '(.*)\.fin1te\.net');
$options->addToList('whitelist', 'scheme', 'ftp');

$curlHandle = curl_init();

//This will now throw an InvalidDomainException
$safeCurl = new SafeCurl($curlHandle, $options);
$response = $safeCurl->execute('http://safecurl.fin1te.net');

//Whilst this will be allowed, and return the response
$safeCurl = new SafeCurl($curlHandle, $options);
$response = $safeCurl->execute('ftp://fin1te.net');

$options = new Options();
$options->enableFollowLocation();

//Abort after 10 redirects
$options->setFollowLocationLimit(10);

$options = new Options();
$options->setIsHeadersIncludedInResponse(true);

use fin1te\SafeCurl\Url;
use fin1te\SafeCurl\Exception;

try {
    $url = 'http://www.google.com';

    $validatedUrl = Url::validateUrl($url);
    $fullUrl = $validatedUrl['url'];
} catch (Exception $e) {
    // URL wasn't safe
}

$options = new Options();
$options->enablePinDns();

$options = new Options();
$options->enablePinDns();

$safeCurl = new SafeCurl($curlHandle, $options);
$response = $safeCurl->execute($url, $headers);

use fin1te\SafeCurl\SafeCurl;
use fin1te\SafeCurl\Exception;
use fin1te\SafeCurl\Options;

$options = new Options();
$options->disableSendCredentials();

$curlHandle = curl_init();

//This will throw an InvalidURLException
$safeCurl = new SafeCurl($curlHandle, $options);
$response = $safeCurl->execute('http://user:[email protected]');