Click here to Skip to main content
13,298,481 members (64,002 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


14 bookmarked
Posted 3 Aug 2009

Free PHP Encoder Application

, 4 Aug 2009
Rate this:
Please Sign up or sign in to vote.
A free PHP encoder application.


This free PHP Encoder Application allows to encode PHP scripts before distributing them. It is all PHP compatible. The encoded scripts are 100% PHP featured, and works on all servers including Windows, Linux, FreeBSD, MacOSX, and others. It is possible to combine encoded and Open Source scripts in one site. The usage of encoded scripts is transparent to your visitors.

This tool allows you to encode immediately, without any installations.


The PHP Encoder Application is a powerful application developed by Illumination to protect your source code. This software will encrypt PHP source code using System.Text.Encoding of the .NET Framework. The PHP code that is encoded by this application is protected against unauthorized modification and theft. The encoding also prevents hackers from looking into your code to find security weaknesses.

Using the code

Now, we are looking for a way to encrypt the PHP code. In C#, you need to have two base functions:

public string Decrypt64(string strToDecrypt)
        byte[] decodedByteArray =
                                                    0, strToDecrypt.Length);
        return Encoding.UTF8.GetString(decodedByteArray);
    catch (Exception ExceptionErr)
        throw new System.Exception(ExceptionErr.Message,


public string Encrypt64(string strToEncrypt)
        byte[] bytInput = Encoding.UTF8.GetBytes(strToEncrypt);
        return Convert.ToBase64String(bytInput);
    catch (Exception ExceptionErr)
        throw new System.Exception(ExceptionErr.Message,

Please download the source code and look at the IEncodePHP class.

  1. Write an error log or any information in the log file. In this article, I write the log file to Log.txt:
  2. string LogFileName = "Log.txt";
    FileInfo f = new FileInfo(LogFileName); 
    StreamWriter writeLog = f.CreateText(); 
    IEncodePHP iEncodePHP = new IEncodePHP(writeLog);

    The constructor of the IEncodePHP class for the write log:

    StreamWriter writeLog;
    public IEncodePHP(){}
    public IEncodePHP(StreamWriter prmWriteLog)
        : base()
        this.writeLog = prmWriteLog;
  3. Create all files and folders in the target folder like the source folder by following a rotation method:
  4. public void GetFileInDirectory(string encodePath, int level, string decodePath)
        DirectoryInfo dir = new DirectoryInfo(encodePath.Trim());
        DirectoryInfo[] directory = dir.GetDirectories();
        FileInfo[] bmpfiles = dir.GetFiles("*.*");
        int totalFile = bmpfiles.Length;
        foreach (FileInfo f in bmpfiles)
            string fileName = f.Name.ToString();
            long lengthOfFile = f.Length;
            DateTime createTimeFile = f.CreationTime;
            FileAttributes fileAttributes = f.Attributes;
            string sourceFilePath = encodePath + @"\" + fileName;
            string encodeFilePath = decodePath + @"\" + fileName;
            if (File.Exists(sourceFilePath))
                if (!File.Exists(encodeFilePath))
                    CreateFile(sourceFilePath, encodeFilePath);
        foreach (DirectoryInfo f in directory)
            string folderName = f.Name.ToString();
            DateTime createTimeFile = f.CreationTime;
            FileAttributes folderAttributes = f.Attributes;
            string strEncodepath = encodePath + @"\" + folderName;
            string strDecodePath = decodePath + @"\" + folderName;
            //Create decode path
            if (!File.Exists(strDecodePath))
                CreateFolder(decodePath, folderName);
            GetFileInDirectory(strEncodepath, level, strDecodePath);
    1. Create a folder:
    2. private void CreateFolder(string parentPath, string folder)
              string path = parentPath + @"\" + folder;
              if (!File.Exists(path))
                  DirectoryInfo dir = new DirectoryInfo(parentPath);
          catch (Exception ex)
              throw ex;
    3. Create a file: Check that the file is a PHP file. If the file is a PHP file, then create a new file, else copy the source files to the target files.
    4. private void CreateFile(string sourceFilePath, string encodeFilePath)
          string sourceExt = GetExtOfFile(sourceFilePath);
          string[] arrExtAllow = { "php", "inc" };//review the rem code // of js
          if (!IsAllowEncode(arrExtAllow, sourceExt))
              File.Copy(sourceFilePath, encodeFilePath, true);
              FileInfo fi = new FileInfo(encodeFilePath);
              FileStream fstr = fi.Create();
              FileInfo f = new FileInfo(encodeFilePath);
              StreamWriter w = f.CreateText();
              StreamReader SR;
              SR = File.OpenText(sourceFilePath);
              encodeFile(SR, w);
  5. Encode the PHP code:
  6. private string EncodePHP(ArrayList arrToEncode)
        string strToEncode = ConvertToString(arrToEncode);
        strToEncode = strToEncode.Replace(IlluminationConstants.newLineScript, "");
        string strEncode1 = EncodePHP(objCrypto.Encrypt64(strToEncode));
        for (int i = 0; i < 4; i++)
            strEncode1 = EncodePHP(objCrypto.Encrypt64(strEncode1));
        return EncodePHP(objCrypto.Encrypt64(strEncode1));
    private string EncodePHP(string strEncoded)
        string variable1 = IRandom.GetRandomString(4, false, false);
        string variable2 = IRandom.GetRandomString(3, false, false);
        string variable3 = IRandom.GetRandomString(2, false, false);
        string startVariable = " $" + variable1 + " = '";
        string endVariable = "';";
        string strDecode = "$" + variable3 + " = '$" + variable2 +
            " = base64_decode($" + variable1 + "); eval($" + variable2 + ");';";
        string strEval = "eval($" + variable3 + ");";
        strEncoded = startVariable + strEncoded + endVariable + strDecode + strEval;
        return strEncoded;

How to encode a PHP file using the Illumination tool?

You can run the Illumination tool by specifying the source directory and the target directory as follows:

  1. Click Browse... in the source to find a folder that contains PHP files.
  2. Click Browse... in the target to find a destination folder that you want the encoded file to be located in.
  3. Click the "Encode" button to encode all PHP files in your selected folder.
  4. Wait for the Congratulation dialog and enjoy your encoded file.

When you start with the "Encode" button, the Illumination tool will encode the files in the source-directory and save the results in the target-directory.

Points of interest

In this tutorial, you learned about the many features of the Illumination tool and how to use them to quickly protect your PHP scripts. Additional technical information is available from the Illumination blog. Visit the following link for more information:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sần Hải Quang
Software Developer (Senior) Bamboo Solutions
Vietnam Vietnam
My full name is Sần Hải Quang. I'm software engineer of Bamboo Solutions. My company is a Microsoft Gold-certified partner, is a leading global provider of SharePoint Web Parts and technologies that extend the power of the SharePoint platform. Over 4,500 organizations worldwide have chosen to enhance their SharePoint deployment with products and solutions from Bamboo. If you have SharePoint, you need Bamboo!

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
VARSHA DAS13-Jan-16 1:52
memberVARSHA DAS13-Jan-16 1:52 
QuestionToo easy to decode! Pin
Tung Nguyen1-Nov-14 6:33
memberTung Nguyen1-Nov-14 6:33 
QuestionTrial or not trial, that's the question. Pin
erm3nda1-Apr-14 14:13
membererm3nda1-Apr-14 14:13 
QuestionCommand Line usage? Pin
erm3nda1-Apr-14 14:11
membererm3nda1-Apr-14 14:11 
QuestionSee a blank page Pin
Member 1040042118-Nov-13 16:32
memberMember 1040042118-Nov-13 16:32 
QuestionThanks Pin
Member 1036124125-Oct-13 22:10
memberMember 1036124125-Oct-13 22:10 
Questionkeep on creating target folder with target file inside the target directory Pin
downpobs4-Nov-12 19:51
memberdownpobs4-Nov-12 19:51 
QuestionWhen i run at localhost there is a problem. can you help me sir? Pin
Member 955160327-Oct-12 23:13
memberMember 955160327-Oct-12 23:13 
AnswerRe: When i run at localhost there is a problem. can you help me sir? Pin
erm3nda1-Apr-14 14:06
membererm3nda1-Apr-14 14:06 
Questionerror " headers already sent by" Pin
syuuzero3-Apr-12 1:20
membersyuuzero3-Apr-12 1:20 
AnswerRe: error " headers already sent by" Pin
Member 1036124125-Oct-13 22:05
memberMember 1036124125-Oct-13 22:05 
QuestionIt works. Pin
fajardwinugroho9-Feb-12 10:01
memberfajardwinugroho9-Feb-12 10:01 
QuestionError - How to use it in webserver? Pin
reyz_wha25-Dec-11 11:18
memberreyz_wha25-Dec-11 11:18 
AnswerRe: Error - How to use it in webserver? Pin
Member 916279710-Jul-12 9:45
memberMember 916279710-Jul-12 9:45 
Questionwhy size of the file php to be large Pin
dewamaya19-Dec-11 23:46
memberdewamaya19-Dec-11 23:46 
GeneralThanks! Pin
JessyWilliams19-Sep-11 1:45
memberJessyWilliams19-Sep-11 1:45 
Generalshowing error Pin
basant12345622-Mar-11 21:27
memberbasant12345622-Mar-11 21:27 
GeneralRe: showing error Pin
Member 105820668-Feb-14 21:16
memberMember 105820668-Feb-14 21:16 
Generalchange another algorithms Pin
NAING19-Dec-10 9:21
memberNAING19-Dec-10 9:21 
GeneralThanks for tool Pin
saurabhaggarwal12-Mar-10 16:42
membersaurabhaggarwal12-Mar-10 16:42 
GeneralRe: Thanks for tool Pin
Sần Hải Quang12-Mar-10 18:14
memberSần Hải Quang12-Mar-10 18:14 
GeneralMy vote of 1 Pin
Anton Levshunov16-Nov-09 5:03
memberAnton Levshunov16-Nov-09 5:03 
GeneralRe: My vote of 1 Pin
Sần Hải Quang12-Mar-10 18:32
memberSần Hải Quang12-Mar-10 18:32 
QuestionDecode/decrypt? Pin
CECUCROTZ2-Nov-09 22:58
memberCECUCROTZ2-Nov-09 22:58 
AnswerRe: Decode/decrypt? Pin
Sần Hải Quang12-Mar-10 18:39
memberSần Hải Quang12-Mar-10 18:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 4 Aug 2009
Article Copyright 2009 by Sần Hải Quang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid