I am sending a link to my user's email to activate his account by click that link. example link: http://test.com/welcome/make_active_user/($user_id)
then I encode $user_id in my controller, after that my link looks like the following one
http://test.com/welcome/make_active_user/17elQOjxrOXDsZdDZVFY7JFrB0TJFojdS+5OTpiIq/XXIaVrDfVWQ7xgOXXqGsURIFe/Udvm/XHrNWtbZXFA2g==
upto this everything is fine. Now i want to decode the $user_id,
but "/" symbol create problem. codeigniter took only those characters before the "/" symbol. How can i get a output of encoded user_id without "/"
I use "$this->encrypt->encode($user_id,$key);" in my controller
Please help
Just pass your encoded $user_id to the php function urlencode() before sending in a link like this:
$user_id_link = urlencode($user_id);
And decode the string you get back from the link with url decode() like this:
$user_id = urldecode($user_id_link);
                        You need to modify the encrypt class to encode url safe strings.
class MY_Encrypt extends CI_Encrypt
{
    function encode($string, $key="", $url_safe=true)
    {
        $ret = parent::encode($string, $key);
        if ($url_safe)
        {
            $ret = strtr(
                    $ret,
                    array(
                        '+' => '.',
                        '=' => '-',
                        '/' => '~'
                    )
                );
        }
        return $ret;
    }
    function decode($string, $key="")
    {
        $string = strtr(
                $string,
                array(
                    '.' => '+',
                    '-' => '=',
                    '~' => '/'
                )
            );
        return parent::decode($string, $key);
    }
}
Then you can create a $url_safe link
Grab the encryption key from your config
$key = $this->config->item('encryption_key');
Create a url safe string by passing true as the third parameter
$encoded_url_safe_string = urlencode($this->encrypt->encode('secret', $key, true));
You will need to use rawurldecode to decode the string
$decoded_url_safe_string = rawurldecode($encoded_url_safe_string, $key);
                        I faced the same problem in the past, codeigniter encrypt->encode()has disallowed chars for URL but i did the following to solve the problem 
encode() your $user_id
decode() your $user_id
here is the code:
$this->encrypt->encode($user_id,$key);
$user_id = strtr($user_id,array('+' => '.', '=' => '-', '/' => '~'));
//your email body (link the user id here)
now time for decoding
$user_id = strtr($user_id,array('.' => '+', '-' => '=', '~' => '/'));
$this->encrypt->decode($user_id,$key);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With