Encode PHP files, How to encode php?

Wednesday, March 28, 2012


PHP Code is our asset of development and concepts. We need to protect / secure our PHP Source code on distribution server. In order to protect PHP source code we need to  encode php files before going to distribute. To encode PHP files to protect PHP source. Here is my solution to protect our PHP Source code with PHP encryption and get Encrypted PHP Source to deploy. In this task we have to use htmlspecialcharsgzdeflatebase64_encodehtml_entity_decodeeval functions



How to encode PHP files and PHP Encoder Online


SourceCode.php   
Put your PHP Source you need to Encode/Protect also include domain based verification code inside this.

<?php
// SAMPLE SOURCE CODE allowed to run only on w3lessons.com
// Start
// PHP Tag in begining and Ending is Must to process encoding...
if(!strstr($_SERVER['HTTP_HOST'],"w3lessons.com"))
die("Unlicenced Domain");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How to Encode php files</title>
</head>

<body>
<?php
echo "<h1>Welcome</h1>";
?>
</body>
</html>
<?php
//End
?>

Encoder.php
Run Encoder.php (Output will create a New File EncodeOutput.php

<?php ob_start();

// Put your Source in this file SourceCode.php
$EncodeFileName = "SourceCode.php";
$EncodeCount = intval(rand(5,72)); // Adjust to improve your code security.

// It will cleated automatically after encoding....
copy($EncodeFileName,"EncodeOutput.php");

for($i=0;$i<=$EncodeCount;$i++)
{
 $phpcode = file_get_contents("EncodeOutput.php");
 //remove space
 $phpcode=trim($phpcode);
 //count string
 $count=strlen($phpcode);
 $last=$count-4;
 $rest = substr($phpcode, 2, $last);
 $display= substr($rest, 4);
 $string= htmlspecialchars($display,ENT_NOQUOTES,'UTF-8');
 $phpcode=stripslashes($phpcode);
 $compressed = gzdeflate($string, 5);
 $encode = base64_encode($compressed);

 $phpcode = "&lt;"."&#63;"."php \n";
 $phpcode .= 'eval(html_entity_decode(gzinflate(base64_decode("'.$encode.'")),ENT_NOQUOTES));';
 $phpcode .= "\n".'?'.'>';

 file_put_contents("EncodeOutput.php",html_entity_decode($phpcode,ENT_NOQUOTES));
 usleep(1000);
}

echo "Encoding Completed ! <br /><br />View <a href=\"EncodeOutput.php\">Encoded Output</a>";

?>



EncodeOutput.php
Backup your Original file and replace the encodeoutput.php content instead of Actual PHP Code



<?php 
eval(html_entity_decode(gzinflate(base64_decode("NVa3ruWGEuv9Ga52IQPKCYaLo5xzbhbKOesoff27zWunGJIAOZy/yjMdfjXHOPwpp6M9nj9Fmc9F+at+26ka0qP8laV7SWD/n/9tJC7Kbc4s9N5bxo+CN/mGOaftTN0Z+fpzbbsFoR1BZKXnpcA3ECIXqsbN7KzLI78WZtArsp00kJV7u407OI4AGrhcpoLAk5lH2UjgCdLH4oxANSqBOMvnwL3p7gerUjkv/l0gF28xEiensPA3wLUnqT+c4Svojbx3E8efTEI2JkJfLBdPNSxHn6fsQPGUipQAPCjOaPWsYq1lAYLp/GLW90X+gEuho+lIIRtikPqlpJ7LuvgOa7MbGKHro9mSi3C4OR4xOjX7fDCrvJ7dXcnrDUc5vC3p6j4HPH1YRTAe56IKX00Nj6Aui0f8qFdEO0T5U6gWDDo8+ciDyzYDZeXg0/Iqf4zeg9tJK0VH+t5vJUSCOGf6OvNkHhCgKa4GmbRqZw8WiYc2NGpm+PNgejggMeeX6sussGa7EyeE3PyN584xf1CT+KLwZkBzRvqK6rhF7EQQVL7TRB2xoOfy6/qjIIZUgcJADG77b+E/7+2DUNMFjQTMF8HxNTp4U4nTNiFfBPwlUB66yEAcQ1Ptpvmy52EL0JU5aHcgW8eIAihGVFPMhIpFAaSaIDXtCUV+Yv0bgvqiOZJhGq9pxI98J5IP29CeS0vsK9ulNQeteDUmqf43PgqARr+McyB8G+smUfvjdoa1ytB1LI0hTFJSDNbTZLyyMk4ZYW9kFcK1HowSLH8vHV61hJZAvyGbZPScaxcuQZFj7oluyZazZYcyyYxjg2VL3OASOUHhTezw++s6Ka0neSO1iJocc41fu7bJJVa7xBo3aXBdxyr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