Category Archives: Uncategorized

How to Enable HTTP/2 on Nginx

It is simple to enable HTTP/2 on Nginx, just replace this: listen 443 ssl;listen 443 ssl; With this: listen 443 ssl http2;listen 443 ssl http2; And reload your Nginx configuration: service nginx reloadservice nginx reload You can find here a complete SSL configuration: Let’s Encrypt on Nginx and SSL Grade A+

Example usage PHP Namespace and Use

Pay attention to the order, namespace goes at first line: namespace LayerShifter\TLDExtract\Tests;   include_once __DIR__ . ‘/vendor/autoload.php’;   use LayerShifter\TLDDatabase\Store; use LayerShifter\TLDExtract\Exceptions\RuntimeException; use LayerShifter\TLDExtract\Extract; use LayerShifter\TLDExtract\Result;   // Below here insert custom functions etc   $extract = new Extract();   $extract->setExtractionMode(Extract::MODE_ALLOW_ICCAN);   $result = $extract->parse(‘a.b.blogspot.com’);   print_r($result->getRegistrableDomain());namespace LayerShifter\TLDExtract\Tests; include_once __DIR__ . ‘/vendor/autoload.php’; use LayerShifter\TLDDatabase\Store; use […]

Composer No version set (parsed as 1.0.0) is satisfiable

If you get these error messages via composer: Your requirements could not be resolved to an installable set of packages. … – The requested package library_name No version set (parsed as 1.0.0) is satisfiable by library_name[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability. … Installation failed, reverting ./composer.json to […]

Install Composer with Curl

Open the folder where is composer.json and then type: curl -sS https://getcomposer.org/installer | phpcurl -sS https://getcomposer.org/installer | php This will create the file composer.phar. To run a composer command type: php composer.phar [command]php composer.phar [command] Example: php composer.phar require php-curl-class/php-curl-classphp composer.phar require php-curl-class/php-curl-class

PHP Validate URL

PHP function that validates and URL: function is_website_url($url, $allowed_schemes = array(‘http’, ‘https’)) { $validate_url = !(filter_var($url, FILTER_VALIDATE_URL) === false); $scheme = parse_url($url, PHP_URL_SCHEME); return $validate_url && in_array($scheme, $allowed_schemes, true); }function is_website_url($url, $allowed_schemes = array(‘http’, ‘https’)) { $validate_url = !(filter_var($url, FILTER_VALIDATE_URL) === false); $scheme = parse_url($url, PHP_URL_SCHEME); return $validate_url && in_array($scheme, $allowed_schemes, true); } Usage: $url […]

PHP Curl Class

Awesome PHP curl class found on github: $ composer require php-curl-class/php-curl-class &> /dev/null $ php –interactive php > require __DIR__ . ‘/vendor/autoload.php’; php > use \Curl\Curl; php > $curl = new \Curl\Curl(); php > $curl->setBasicAuthentication(‘user’, ‘pass’); php > $curl->get(‘https://api.github.com/user’); php > echo $curl->httpStatusCode; 200 php > echo $curl->responseHeaders[‘content-type’]; application/json; charset=utf-8 php > echo $curl->response->login; php-curl-class […]

Example FFprobe commands

Extract index, codec name and codec type: ffprobe -v error -show_entries stream=index,codec_name,codec_type input.mkvffprobe -v error -show_entries stream=index,codec_name,codec_type input.mkv Example output: [STREAM] index=0 codec_name=h264 codec_type=video [/STREAM] [STREAM] index=1 codec_name=vorbis codec_type=audio [/STREAM] [STREAM] index=2 codec_name=vorbis codec_type=audio [/STREAM] [STREAM] index=3 codec_name=vorbis codec_type=audio [/STREAM] [STREAM] index=4 codec_name=ass codec_type=subtitle [/STREAM][STREAM] index=0 codec_name=h264 codec_type=video [/STREAM] [STREAM] index=1 codec_name=vorbis codec_type=audio [/STREAM] [STREAM] […]

Check if a website is located in China

To check if a website is located in China you can parse the NS DNS records: host => rbacc-us.com class => IN ttl => 86400 type => NS target => f1g1ns1.dnspod.net   host => rbacc-us.com class => IN ttl => 86400 type => NS target => f1g1ns2.dnspod.nethost => rbacc-us.com class => IN ttl => 86400 […]

Google SafeBrowsing v4 PHP Example

Sample PHP function to check Google SafeBrowsing v4 API: function Lookup_GoogleSafeBrowsing_v4($url) { $data = ‘{ "client": { "clientId": "TestClient", "clientVersion": "1.0" }, "threatInfo": { "threatTypes": ["MALWARE", "SOCIAL_ENGINEERING"], "platformTypes": ["LINUX"], "threatEntryTypes": ["URL"], "threatEntries": [ {"url": "’.$url.’"} ] } }’;   $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://safebrowsing.googleapis.com/v4/threatMatches:find?key=ENTER_YOUR_API_KEY_HERE"); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", […]

Calculate Page Load Time in PHP

Simple way to calculate page load time in PHP: $time_start = microtime(true);   // Do all your stuff and procedures here   $time_end = microtime(true); $time = number_format( $time_end – $time_start, 2 );   echo "<!– Page loaded in ".out($time)." seconds –>";$time_start = microtime(true); // Do all your stuff and procedures here $time_end = microtime(true); […]