Update: The obfuscator download is not active anymore.
You may need to obfuscate your PHP code for security or licensing reasons, so other third parties cannot easily hijack your code for their own purposes. Obfuscated code is source or machine code that has been made difficult to understand for humans. So if you’re planning to sell your PHP script, make sure you obfuscate it for security and licensing reasons.
There are a lot of tools for obfuscating PHP scripts. The 2 best tools on the net right now are IonCube Encoder and Zend Guard. But unfortunately they are not free, and you need to install the IonCube loader or Zend Guard loader module on the server so the obfuscated code can be read properly.
If you are developing a small PHP project then I suggest you use the free PHP Obfuscator instead of IonCube Encoder or Zend Guard. You can use the PHP Obfuscator from Raizlabs; it is light and free. I love free software, and I bet you do too 🙂
Screenshot:

Here is the sample:
getbrowser.php
function getBrowser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";
//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
$platform = 'linux';
}
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
$platform = 'mac';
}
elseif (preg_match('/windows|win32/i', $u_agent)) {
$platform = 'windows';
}
// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
{
$bname = 'Internet Explorer';
$ub = "MSIE";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$bname = 'Mozilla Firefox';
$ub = "Firefox";
}
elseif(preg_match('/Chrome/i',$u_agent))
{
$bname = 'Google Chrome';
$ub = "Chrome";
}
elseif(preg_match('/Safari/i',$u_agent))
{
$bname = 'Apple Safari';
$ub = "Safari";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$bname = 'Opera';
$ub = "Opera";
}
elseif(preg_match('/Netscape/i',$u_agent))
{
$bname = 'Netscape';
$ub = "Netscape";
}
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $u_agent, $matches)) {
// we have no matching number just continue
}
// see how many we have
$i = count($matches['browser']);
if ($i != 1) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
$version= $matches['version'][0];
}
else {
$version= $matches['version'][1];
}
}
else {
$version= $matches['version'][0];
}
// check if we have a number
if ($version==null || $version=="") {$version="?";}
return array(
'userAgent' => $u_agent,
'name' => $bname,
'version' => $version,
'platform' => $platform,
'pattern' => $pattern
);
}
// now try it
$ua=getBrowser();
$yourbrowser= "Your browser: " . $ua['name'] . " " . $ua['version'] . " on " .$ua['platform'] . " reports: <br >" . $ua['userAgent'];
print_r($yourbrowser);
var_dump($ua);
Obfuscated code:
/* This file encoded by Raizlabs PHP Obfuscator http://www.raizlabs.com/software */
function FCFA1126BBD6006F3F3CA454ED1DF2781() { $RD3EDD54BF7F748F7C341993E5E16FBE4 = $_SERVER['HTTP_USER_AGENT']; $R936F519EB526FBE7AD6FFC1C022A0202 = 'Unknown'; $RF35DD214BA0E512C4E40F4936F263F63 = 'Unknown'; $RC4B8AB500089B24B2D72685C7B9F7AC0= ""; //First get the platform?
if (preg_match('/linux/i', $RD3EDD54BF7F748F7C341993E5E16FBE4)) { $RF35DD214BA0E512C4E40F4936F263F63 = 'linux'; } elseif (preg_match('/macintosh|mac os x/i', $RD3EDD54BF7F748F7C341993E5E16FBE4)) { $RF35DD214BA0E512C4E40F4936F263F63 = 'mac'; } elseif (preg_match('/windows|win32/i', $RD3EDD54BF7F748F7C341993E5E16FBE4)) { $RF35DD214BA0E512C4E40F4936F263F63 = 'windows'; } // Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$RD3EDD54BF7F748F7C341993E5E16FBE4) && !preg_match('/Opera/i',$RD3EDD54BF7F748F7C341993E5E16FBE4)) { $R936F519EB526FBE7AD6FFC1C022A0202 = 'Internet Explorer'; $R6EC2C3E4F1A67ECC8AD64C6F8873B4B7 = "MSIE"; } elseif(preg_match('/Firefox/i',$RD3EDD54BF7F748F7C341993E5E16FBE4)) { $R936F519EB526FBE7AD6FFC1C022A0202 = 'Mozilla Firefox'; $R6EC2C3E4F1A67ECC8AD64C6F8873B4B7 = "Firefox"; } elseif(preg_match('/Chrome/i',$RD3EDD54BF7F748F7C341993E5E16FBE4)) { $R936F519EB526FBE7AD6FFC1C022A0202 = 'Google Chrome'; $R6EC2C3E4F1A67ECC8AD64C6F8873B4B7 = "Chrome"; } elseif(preg_match('/Safari/i',$RD3EDD54BF7F748F7C341993E5E16FBE4)) { $R936F519EB526FBE7AD6FFC1C022A0202 = 'Apple Safari'; $R6EC2C3E4F1A67ECC8AD64C6F8873B4B7 = "Safari"; } elseif(preg_match('/Opera/i',$RD3EDD54BF7F748F7C341993E5E16FBE4)) { $R936F519EB526FBE7AD6FFC1C022A0202 = 'Opera'; $R6EC2C3E4F1A67ECC8AD64C6F8873B4B7 = "Opera"; } elseif(preg_match('/Netscape/i',$RD3EDD54BF7F748F7C341993E5E16FBE4)) { $R936F519EB526FBE7AD6FFC1C022A0202 = 'Netscape'; $R6EC2C3E4F1A67ECC8AD64C6F8873B4B7 = "Netscape"; } // finally get the correct version number
$RE9C4E610341A88DB0846498C2C422A2D = array('Version', $R6EC2C3E4F1A67ECC8AD64C6F8873B4B7, 'other'); $R1DD288014A4DB47D1D475344526959BE = '#(?<browser>' . join('|', $RE9C4E610341A88DB0846498C2C422A2D) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#'; if (!preg_match_all($R1DD288014A4DB47D1D475344526959BE, $RD3EDD54BF7F748F7C341993E5E16FBE4, $R2BC3A0F3554F7C295CD3CC4A57492121)) { // we have no matching number just continue
} // see how many we have
$RA16D2280393CE6A2A5428A4A8D09E354 = count($R2BC3A0F3554F7C295CD3CC4A57492121['browser']); if ($RA16D2280393CE6A2A5428A4A8D09E354 != 1) { //we will have two since we are not using 'other' argument yet //see if version is before or after the name
if (strripos($RD3EDD54BF7F748F7C341993E5E16FBE4,"Version") < strripos($RD3EDD54BF7F748F7C341993E5E16FBE4,$R6EC2C3E4F1A67ECC8AD64C6F8873B4B7)){ $RC4B8AB500089B24B2D72685C7B9F7AC0= $R2BC3A0F3554F7C295CD3CC4A57492121['version'][0]; } else { $RC4B8AB500089B24B2D72685C7B9F7AC0= $R2BC3A0F3554F7C295CD3CC4A57492121['version'][1]; } } else { $RC4B8AB500089B24B2D72685C7B9F7AC0= $R2BC3A0F3554F7C295CD3CC4A57492121['version'][0]; } // check if we have a number
if ($RC4B8AB500089B24B2D72685C7B9F7AC0==null || $RC4B8AB500089B24B2D72685C7B9F7AC0=="") {$RC4B8AB500089B24B2D72685C7B9F7AC0="?";} return array( 'userAgent' => $RD3EDD54BF7F748F7C341993E5E16FBE4, 'name' => $R936F519EB526FBE7AD6FFC1C022A0202, 'version' => $RC4B8AB500089B24B2D72685C7B9F7AC0, 'platform' => $RF35DD214BA0E512C4E40F4936F263F63, 'pattern' => $R1DD288014A4DB47D1D475344526959BE ); } // now try it
$RE63F6556DE280F4131E2A6E2926023BE=FCFA1126BBD6006F3F3CA454ED1DF2781(); $R642BF308CE21E5227B53E275079F34C5= "Your browser: " . $RE63F6556DE280F4131E2A6E2926023BE['name'] . " " . $RE63F6556DE280F4131E2A6E2926023BE['version'] . " on " .$RE63F6556DE280F4131E2A6E2926023BE['platform'] . " reports: <br >" . $RE63F6556DE280F4131E2A6E2926023BE['userAgent']; print_r($R642BF308CE21E5227B53E275079F34C5); var_dump($RE63F6556DE280F4131E2A6E2926023BE);
See the result example here:
getbrowser.php
getbrowser-obfuscated.php
Download Raizlabs PHP Obfuscator
