PHP code example of nggit / php-simple-client

1. Go to this page and download the library: Download nggit/php-simple-client 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/ */

    

nggit / php-simple-client example snippets



$client = new Nggit\PHPSimpleClient\Curl();


$client = new Nggit\PHPSimpleClient\Stream();


use Nggit\PHPSimpleClient\Client;

$client = Client::create(); // default backend is 'stream'
$client = Client::create('curl'); // if you want to use the 'curl' backend
// alternative way:
$client = (new Client())->stream();
// you can also use the options:
$client = (new Client(['debug' => true, 'timeout' => 60]))->curl();
$client = (new Client())->curl(true, -1, 60); // debug, maxredirs, timeout

$client->setUrl('https://www.google.com/') // # HTTP/1.1 200 OK
# Date: Mon, 11 Feb 2019 07:18:28 GMT
# Expires: -1
# Cache-Control: private, max-age=0
# Content-Type: text/html; charset=UTF-8
# ...

echo $client->getHeader(0);
# HTTP/1.1 200 OK

echo $client->getHeader('Content-Type');
# text/html; charset=UTF-8

print_r($client->getHeaders()); // array

echo $client->getBody();
# <!doctype html>...</html>

$client->setUrl('https://www.google.com/') // 

$headers = array(
    'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language: en-US,en;q=0.5'
);

$client->setHeaders($headers);

echo $client->getProtocol();        # HTTP
echo $client->getProtocolVersion(); # 1.1
echo $client->getStatusCode();      # 200
echo $client->getReasonPhrase();    # OK

$url = 'https://mbasic.facebook.com/login/device-based/regular/login/?next=https%3A%2F%2Fmbasic.facebook.com%2Fmessages';
$client->setUrl($url);
$client->setHeaders($headers); // you can use headers above
$client->request('POST', array('email' => 'YOUR_USER_NAME_OR_EMAIL', 'pass' => 'YOUR_PASSWORD'));
$client->send(); // send the request

echo $client->getBody(); // display the last page of redirects

composer