Category Archives: Uncategorized

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

Replace multiple spaces with a single space in PHP

Replace multiple spaces with a single space: $string = preg_replace(‘/\s+/’, ‘ ‘, $string);$string = preg_replace(‘/\s+/’, ‘ ‘, $string); For UTF-8 strings use: $string = preg_replace(‘/\s+/u’, ‘ ‘, $string);$string = preg_replace(‘/\s+/u’, ‘ ‘, $string);

Print all HTTP POST variables\values in PHP

Show all variables sent via HTTP POST in PHP: print_r($_POST);print_r($_POST); A better way is to use a table to show the key and value: echo ‘<table>’; foreach ($_POST as $key => $value) { echo "<tr><td>".htmlspecialchars($key)."</td><td>".htmlspecialchars($value)."</td></tr>"; } echo ‘</table>’;echo ‘<table>’; foreach ($_POST as $key => $value) { echo "<tr><td>".htmlspecialchars($key)."</td><td>".htmlspecialchars($value)."</td></tr>"; } echo ‘</table>’; Or simply show key […]

PHP Truncate all words longer than and add ellipsis

function truncate_all_long_strings($string, $limit = 10) { return preg_replace("/(\\b\\w{".intval($limit)."})\\w+\\b/", "$1…", $string); }function truncate_all_long_strings($string, $limit = 10) { return preg_replace("/(\\b\\w{".intval($limit)."})\\w+\\b/", "$1…", $string); } Example usage: echo truncate_all_long_strings("veryyyyyyyyyyyyyyyyyyyyyyyyy long strinnnnnnnnnnnnnnnnnnnnnnngs to testtttttttttttttttttt");echo truncate_all_long_strings("veryyyyyyyyyyyyyyyyyyyyyyyyy long strinnnnnnnnnnnnnnnnnnnnnnngs to testtttttttttttttttttt"); Example output: veryyyyyyy… long strinnnnnn… to testtttttt…veryyyyyyy… long strinnnnnn… to testtttttt…

Adsense high CTR attack (click bombing) April 20 2015

From yesterday I noticed a high CTR on Google Adsense dashboard: That is too good to be true and infact it is a click-bombing attack as referred by other sites. Basically, some bad users are using automated spam bots to visit your website to automatically click on Adsense banners, most probably with the intent to […]

CSS3Pie Basic Usage

CSS3Pie makes IE 6-9 capable of rendering some CSS3 decoration features. Example usage: form[role=login] { border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; behavior: url(PIE.htc); /*CSS3Pie*/ }form[role=login] { border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; behavior: url(PIE.htc); /*CSS3Pie*/ } In case of problems, add position and zoom property: form[role=login] button { behavior: url(PIE.htc); /*CSS3Pie*/ position: relative; /*CSS3Pie*/ zoom: […]