Category Archives: Uncategorized

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 […]

PHP Validate URL

Quick PHP function to validate an URL: if(filter_var($url, FILTER_VALIDATE_URL)) { echo "URL is a valid URL"; } else { echo "URL is not a valid URL"; }if(filter_var($url, FILTER_VALIDATE_URL)) { echo "URL is a valid URL"; } else { echo "URL is not a valid URL"; } Reference: http://php.net/manual/en/filter.filters.validate.php Best PHP function that validates an 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); […]

Call to undefined function idn_to_utf8()

If you get this PHP error message with PHP 7.0: PHP Fatal error: Uncaught Error: Call to undefined function idn_to_utf8()PHP Fatal error: Uncaught Error: Call to undefined function idn_to_utf8() You need to install php7.0-intl module: apt-get install php7.0-intlapt-get install php7.0-intl

Comply with the EU Cookie Law with Cookie Consent

Cookie Consent is a free and tiny JavaScript plugin for alerting users about the use of cookies on your website. It is designed to help you comply with the EU Cookie Law. The plugin is created by Insites, a registered trademark of Silktide Ltd. Useful links for Cookie Consent: More Information About Cookie Consent Download […]