deemer deemer - 11 months ago 113
PHP Question

Codeigniter ecryption without slash

I know this may look like duplicate from this question : Ignore slash while using encryption in Codeigniter. But I still didn't have the answer from it.

I want to sent encrypted email name as URL to their email account.
Then that URL is decrypted to search if that email name is exist in my database to permit that email into my system.

The problem is :

  1. If I use urlencode or base64_encode after encryption, it always resulted in empty value to search the database after decrypt. I think it because the encrypted value always changing.

  2. If I use the casual encryption, it might have the ("/") character.

  3. If I only use the encode, without the encryption, it might permit the email name to have access into my system.

Lastly, I found some library : Ignore Slash while using encryption in codeigniter - GitHub .

But it gave me this error : Undefined property: CI_Loader::$my_encrypt

I don't know what I've done wrong, I already :

  1. Capitalized the class name first letter.

  2. Using the same file name with the class name. (capitalized too)

  3. Change the extend to CI_Encryption because the Encrypt class is already deprecated.

  4. Insert the
    public function __construct() {parent::__construct();}
    before all method.

  5. Place the file inside application/library.

  6. Load the library

  7. Load the method using
    this is the line that gave me an error.

I know that this may sound like a simple mistake, but I'm using another third-party library too but it didn't give me an error at all.

Can anyone help me find the mistake / missing step there? Any help is appreciated.

Update -
Before I load the library in the controller, I want to check the result first in view. But it doesn't give me any changes even when I put the code inside controller. Here is the code :

$key = '';

$segment = $this->my_encrypt->encode($key);
echo $segment;
echo ( $this->my_encrypt->decode($segment) );

Update :
Fix library code to extend with CI_Encryption library

Answer Source

fixed to extend the CI_Encryption library, sorry for bothering. :)

class MY_Encrypt extends CI_Encryption
 * Encodes a string.
 * @param string $string The string to encrypt.
 * @param string $key[optional] The key to encrypt with.
 * @param bool $url_safe[optional] Specifies whether or not the
 *                returned string should be url-safe.
 * @return string
public function __construct() {

function encode($string)
    $ret = parent::encrypt($string);

    if ( !empty($string) )
        $ret = strtr(
                    '+' => '.',
                    '=' => '-',
                    '/' => '~'

    return $ret;

 * Decodes the given string.
 * @access public
 * @param string $string The encrypted string to decrypt.
 * @param string $key[optional] The key to use for decryption.
 * @return string
function decode($string)
    $string = strtr(
                '.' => '+',
                '-' => '=',
                '~' => '/'

    return parent::decrypt($string);