Block badAgents on site

PHP is very powerful language to block bad agents. Below is the code to avoid webspider using PHP in_array().

<?php
$badAgents
= array(‘Acunetix Web Vulnerability Scanner’, ‘Bot\ mailto:craftbot@yahoo.com’, ‘ChinaClaw’, ‘Custo’, ‘DISCo’, ‘Download\ Demon’, ‘eCatch’, ‘EirGrabber’, ‘EmailSiphon’, ‘EmailWolf’, ‘Express\ WebPictures’, ‘ExtractorPro’, ‘EyeNetIE’, ‘FlashGet’, ‘GetRight’, ‘GetWeb!’, ‘Go!Zilla’, ‘Go-Ahead-Got-It’, ‘GrabNet’, ‘Grafula’, ‘HMView’, ‘HTTrack’, ‘Image\ Stripper’, ‘Image\ Sucker’, ‘Indy\ Library’, ‘InterGET’, ‘Internet\ Ninja’, ‘JetCar’, ‘JOC\ Web\ Spider’, ‘larbin’, ‘LeechFTP’, ‘Mass\ Downloader’, ‘MIDown\ tool’, ‘Mister\ PiX’, ‘Navroad’, ‘NearSite’, ‘NetAnts’, ‘NetSpider’, ‘Net\ Vampire’, ‘NetZIP’, ‘Octopus’, ‘Offline\ Explorer’, ‘Offline\ Navigator’, ‘PageGrabber’, ‘Papa\ Foto’, ‘pavuk’, ‘pcBrowser’, ‘RealDownload’, ‘ReGet’, ‘SiteSnagger’, ‘SmartDownload’, ‘SuperBot’, ‘SuperHTTP’, ‘Surfbot’, ‘tAkeOut’, ‘Teleport\ Pro’, ‘VoidEYE’, ‘Web\ Image\ Collector’, ‘Web\ Sucker’, ‘WebAuto’, ‘WebCopier’, ‘WebFetch’, ‘WebGo\ IS’, ‘WebLeacher’, ‘WebReaper’, ‘WebSauger’, ‘Website\ eXtractor’, ‘Website\ Quester’, ‘WebStripper’, ‘WebWhacker’, ‘WebZIP’, ‘Wget’, ‘Widow’, ‘WWWOFFLE’, ‘Xaldon\ WebSpider’, ‘Zeus’);
if(
in_array($_SERVER[‘HTTP_USER_AGENT’],$badAgents)) {
exit();
}
?>
 

UTF-8 FTP Tools

FTP Tools / Clients are most useful for transferring files and data to server.

There are many FTP clients used in File Transfer, please use wikipedia.org for more details…

http://en.wikipedia.org/wiki/Comparison_of_FTP_client_software

Some time file transfer is not secure and reliable using various tools, file become corrupted or some special characters added to files.

You have to use UTF8 encoding while files transfer. Only some FTP tools use UTF8 encoding while uploading and downloading files.

To remove special chars from live sites, you have to use UTF8 based FTP tools.

http://www.pureftpd.org/project/pure-ftpd

http://winscp.net/forum/viewtopic.php?t=7078

http://www.xlightftpd.com/

FileZilla now have UTF8 support. So, next time while you are creating webpages in different languages; you can use UTF-8 based FTP tools to avoid characters problems 😉

Override PHP Function

PHP have PECL (PHP Extension & Community Library) function to override built-in functions by replacing them in the symbol table.

bool override_function ( string $function_name , string $function_args , string $function_code )

 

  1. <?php
  2. override_function(‘strlen’, ‘$string’, ‘return override_strlen($string);’);
  3. function override_strlen($string){
  4. return strlen($string);
  5. }
  6. ?>

The above function “override_function()” require APD i.e. Advanced PHP Debugger.

We can find more about APD here…
http://pecl.php.net/package/apd

Linux users can install apd using below command

# pecl install apd

There is an alternate way to override PHP functions, we can use below class “override” to override any built-in PHP function if PECL is not installed on server 😉

 

  1. <?php
  2. $or = new override ();
  3. $or->override_function(‘strlen’, ‘override_strlen‘, ‘return override_strlen($string);’);
  4. function override_strlen($string){
  5. return strlen($string);
  6. }
  7. ?>

 

 

<?php

$url = 'https://www.svnlabs.com';
$override = new override();

 

$override->override_function('file_get_contents','fileGetContents',$url);

if ($over_func_name = $override->override_check('file_get_contents')) {
    $result=call_user_func($over_func_name, $url);
}

function fileGetContents($url)
{
  /// statements
}

?>

 

PHP Function OverRide Class

<?php 


class override 
{ 

var $functions = array(); 
var $includes = array(); 

function override_function($override, $function, $include) { 
 if ($include) { 
 $this->includes[$override] = $include; 
 } 
 else if (isset($this->includes[$override])) { 
  unset($this->includes[$override]); 
 } 
 $this->functions[$override] = $function; 
} 


function override_check($override) { 
 if (isset($this->includes[$override])) { 
 if (file_exists($this->includes[$override])) { 
 include_once($this->includes[$override]); 
} 

if (function_exists($this->functions[$override])) {
 return $this->functions[$override]; 
} 
else 
{ 
 return false; 
} 
} 
else 
{ 
return false; 
} 
} 
} 

?>

Make a habit of creating things modular, that means “pluggable” and “unpluggable”.