Skip to content

SrvClick/SCURL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SCURL

Easy PHP CURL Library

Installation

composer require srvclick/scurl

IMPORT

use Srvclick\Scurl\Scurl_Request as SCURL;

Examples

GET REQUEST

$curl = new SCURL;
$curl->setUrl('https://example.com');
$response = $curl->Send();
echo $response->getBody();

POST REQUEST

$curl->setMethod("POST");
$curl->setParameters([
    'user' => 'user',
    'password' => 'password',
]);

Custom Method

$curl->setConfigs([
    'custom_method' => 'PUT'
])

SET PROXY

WITHOUT AUTH
$curl->setProxy([
    'proxy' => '127.0.0.1',
    'proxy_port' => '9090'
]);
WITH AUTH
$curl->setProxy([
    'proxy' => '127.0.0.1',
    'proxy_port' => '9090',
    'proy_user' => 'root',
    'proxy_pass' => 'toor'
]);

SET USER-AGENT

Option 1
$curl->setConfigs([
    'user-agent' => 'Mozilla'
])
Option 2
$curl->setHeaders([
    'user-agent: Mozilla'
])

SSL VERIFY PEER

$curl->setConfigs([
    'ssl_verifypeer' => 'false'
]);

USE COOKIES

$this->curl->useCookie(true);
$curl->setCookieName('Random Cookie Name');

DOWNLOAD FILES

$curl->downloadFile("/path/","filename.ext");

INTERCEPT COOKIES

$curl->setInterceptCookie(true);
$responseCookies = $response->getResponseCoookies(); //Array

AVAILABLE CONFIGURATIONS

$curl->setConfigs([
    'use_proxy' => true,
    'max_redirs' => 10,
    'timeout' => 30,
    'http_version' => CURL_HTTP_VERSION_1_1,
    'return_transfer' => true,
    'ssl_verifypeer' => true,
    'follow' => false,
    'encondig' => "",
    'user-agent' => 'SCURL by SrvClick',
    'header' => [],
    'http_auth' => true,
    'http_user' => 'admin',
    'http_pass' => 'admin'
]);

MULTI CURL SUPPORT

$curl = new SCURL();
$curl->setMulticurl();
for ($i = 0; $i < 10; $i++) {
    $curl->MultiUrl('https://jsonplaceholder.typicode.com/todos/'.$i);
    $curl->downloadFile(__DIR__."/downloads/","item_".$i.".json");
}
$response = $curl->Send();
for ($i = 0; $i < $response->getCount(); $i++) {
    echo "Peticion ".$i." Con HTTP STATUS ".$response->getStatus($i)."\n";
}

NIP SUPPORT

$curl->NipSetRange($core, $limit);
$curl->NipMultiUrl('https://example.com/nip');
$curl->NipSetParams(function($nip){
        return ['otp' => str_pad($nip ,4,0,STR_PAD_LEFT)];
        //return '{"nip":"'.str_pad($nip ,4,0,STR_PAD_LEFT).'"}'; //Example 2
    }
$response = $curl->Send();

if($response->checkNip(function ($response) {
    $decode = json_decode($response,true);
    if ($decode['success'] == "yes") return true;
    return false;
})){
    echo "NIP: ".$response->getNip()."\n";
}else{
    echo "Nip not found\n";
}
);