Use Ioncube HTML Encoder to CodeIgniter

Posted by Darwin Biler on October 13, 2013

If you want to obfuscate your HTML markup and you want to use the Ioncube's HTML encoder, this is a quickfix on how to make it work at least in CodeIgniter.

These are the versions of the software that I had tested with this setup:

Ubuntu 13.04 - http://www.ubuntu.com/
PHP 5.4.9 http://www.php.net/
CI 2.1.4 - http://ellislab.com/codeigniter
Obfuscating HTML Encoder 1.9 by IonCube - http://www.ioncube.com/html_encoder.php

I'm not sure with other version combinations, but most likely it will work in your end as well.

Disclaimer: Ok, ok, I know now that PHP 5.3 and 5.4 is coming, there is a lot of new things that comes along. I know CodeIgniter is not maintained anymore and Laravel is taking over already. However, there are tons of web apps there that are still running in CI, and not all company is able to rewrite their whole thing to newer framework. This is for those who will deal with CI, and I emphasize, do not use this instructions when there is a better/cleaner option since this one requires modifying some core files of CI.

So here are the steps.

1. Check the server if it has Ioncube Loader installed. This can be done by putting a php script in the webserver with the following code on it:


Look for this particular area (or you can do a search of "Zend Scripting Language Engine")

zend_setting

see that "ionCube PHP Loader v4.4.3" part? that indicates that IonCube is already installed. That needs to be installed since the encoder itself to be added in your application is an encoded file. Without the ionCube loader installed, the server wont be able to figure out how to execute the encoder file.

2. (Follow these instructions if you dont have ionCube Loader installed)

login to linux terminal and execute the following commands:

cd /usr/local
sudo wget http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
sudo tar xzf ioncube_loaders_lin_x86-64.tar.gz

Check the module is added and enabled in the php configuration file by :

sudo cat /etc/php5/conf.d/ioncube.ini

You should see this in there

zend_extension=/usr/local/ioncube/ioncube_loader_lin_5.4.so

If not, then manually add that line there. Make sure you check the version number matches with your PHP version. If PHP is 5.4 then the file enabled should be ioncube_loader_lin_5.4.so not ioncube_loader_lin_5.3.so

Restart apache for the new settings to take effect

sudo /etc/init.d/apache2 restart

check again the phpinfo on step 1 to make sure the ioncube is showing up now.

3. Download the encoder file in http://www.ioncube.com/html_encoder.php
(i used the http://www.ioncube.com/html_encoder_1.9.zip)
Extract it to your local disk. the encoder file is html_encoder_1.9.php
Note: that is a binary file! don't open it in a text editor since you could accidentally corrupt it.
Save it on CI project on this folder /application/hooks/

4. In your CodeIgniter, you need to enable hooks
application/config/config.php

$config['enable_hooks'] = TRUE;

5. Then define a hook
application/config/hooks.php

$hook['display_override'] = array(
				'class'    => 'IoncubeHTMLEncoder',
				'function' => 'obfuscate',
				'filename' => 'IoncubeHTMLEncoder.php',
				'filepath' => 'hooks'
				);

6. Test the page.
if you got a blank page. check the apache error log

 sudo tail -n 10 /var/log/apache2/error.log

if you see stuffs like "Cannot use output buffering in output buffering display handlers"
edit the system/core/Exceptions.php
(I know you can override core classes by putting a class in the application/core instead of editing the core files, but for some reason, that didn't worked for me)
Edit the lines 181 and 184 so that the ob_start and ob_end_clean is commented out

  //ob_start();
  include(APPPATH.'errors/error_php.php');
  $buffer = ob_get_contents();
  //ob_end_clean();

(I know this is a dirty way of fixing up things, that is why I call this a quickfix. Use this instructions only in case of emergency)

7. Reload again your CI app and see if you are not getting a blank page anymore.

That's all I know.


Did you find this useful?

I'm always happy to help! You can show your support and appreciation by Buying me a coffee (I love coffee!).