PHP Classes

PHP Obfuscator Code: Obfuscate PHP code using base64 and compression

Recommend this page to a friend!
  Info   View files Documentation   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-01-25 (1 month ago) RSS 2.0 feedStarStarStarStar 70%Total: 332 This week: 6All time: 6,899 This week: 98Up
Version License PHP version Categories
obfuscator-php-class 1.4Freely Distributable5PHP 5, Text processing, Code Generation
Description Author

This class can obfuscate PHP code using base64 and compression.

It takes a given string of PHP code and generates another code obfuscating the input code.

When running the obfuscated code, it is equivalent to run the original code.

Name: Pierre-Henry Soria <contact>
Classes: 13 packages by
Country: United Kingdom United Kingdom
Age: 27
All time rank: 64132 in United Kingdom United Kingdom
Week rank: 40 Up4 in United Kingdom United Kingdom Up


PHP Obfuscator

Simple and effective Obfuscator PHP class (this is not a stupid base64 encoding script, but a real and effective obfuscation script)


If you want to keep your open source code private, but working on all Web hosting. This Obfuscator class is the obfuscator you need!

Not easy readable by developers (unless they are ready to spend lot of time). This will really discourage them :smiley:


Example 1

require 'src/Obfuscator.php';

$sData = <<<'DATA'
    echo 'This is my PHP code, can be class class, interface, trait,... in PHP 5, 7, 7.2, ..., etc.';

$sObfusationData = new Obfuscator($sData, 'Class/Code NAME');
file_put_contents('my_obfuscated_data.php', '<?php ' . "\r\n" . $sObfusationData);

Example 2

require 'src/Obfuscator.php';

$sData = <<<'DATA'
    $hour = date('H');

    echo 'The hour (of the server) is ' . date('H:m');
    echo ', and will give the following message:<br><br>';

    if ($hour < 10) {
        echo 'Have a good morning!';
    } elseif ($hour < 20) {
        echo 'Have a good day!';
    } else {
        echo 'Have a good night! zZz z';

$sObfusationData = new Obfuscator($sData, 'Give a name to the piece of code you want to obfuscate');
file_put_contents('obfuscated_code.php', '<?php ' . "\r\n" . $sObfusationData);

Run obfuscated_code.php file and you will see something like below:

The hour (of the server) is 19, and will give the following message: Have a good day!

Example 3

require 'src/Obfuscator.php';

$filename = 'myphpfile'; // A PHP filename (without .php) that you want to obfuscate

$sData = file_get_contents($filename . '.php');
$sData = str_replace(array('<?php', '<?', '?>'), '', $sData); // Strip PHP open/close tags
$sObfusationData = new Obfuscator($sData, 'Class/Code NAME');
file_put_contents($filename . '_obfuscated.php', '<?php ' . "\r\n" . $sObfusationData);


  • PHP 5.2 or higher (works with PHP 7.*+ as well!)


I first created it for my needs, especially for the license file of my pH7CMS Software in early 2014 but now (summer 2016), I don't need to keep this project private and want to share it for the others (hoping it will help you and saving time!).

I did change anything since the first version and didn't review it, so could be improved. Feel free to add your improvements by forking it and create a new PR. It will be a pleasure for me to see your contribution!

FYI, in 3 years, I never found my obfuscated code unobfuscated (and one project which is pH7CMS had been downloaded by over 50,000 users) so you can be quite confident (however as you can understand, I cannot give any guarantee on it).

Who I am?

I'm Pierre-Henry Soria, Software Developer, love learning new things every single day and also passionate about e-businesses and e-marketing.

How Contacting Me?

You can by email at pierrehenrysoria+github [[AT]] gmail [[D0T]] com

The License

The script is under Creative Commons Attribution 3.0 license or later; See the LICENSE.txt file.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.txt Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Obfuscator.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file expected-data.txt Doc. Documentation
  Plain text file ObfuscatorTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:6
All time:6,899
This week:98Up
User Ratings User Comments (1)
 All time