0

i want to encrypt our url parameters on one page and decrypt on other page for security reason. when i try this then disallowed character error occurs. also i do not want to set $config['permitted_uri_chars']. according to this.

please give me solution that i can able to encrypt parameters with url like-

wwww.domain.com/controller_name/method_name/parameter1/parameter2

and i am using like for encrypt url-

<a href="<?php echo site_url('C_Name/M_Name/'.$this->encrypt->encode($id)); ?>">Link</a>

and i am using like for decrypt url-

echo $this->encrypt->decode($id)

other issue is that its value is being changed randomly.

Please make me understand that how to do this.

Thanks.

4

2 Answers 2

5

STEP 1: Please create a helper function in helper folder

function encode_url($string, $key="", $url_safe=TRUE)
{
    if($key==null || $key=="")
    {
        $key="tyz_mydefaulturlencryption";
    }
      $CI =& get_instance();
    $ret = $CI->encrypt->encode($string, $key);

    if ($url_safe)
    {
        $ret = strtr(
                $ret,
                array(
                    '+' => '.',
                    '=' => '-',
                    '/' => '~'
                )
            );
    }

    return $ret;
}
  function decode_url($string, $key="")
{
     if($key==null || $key=="")
    {
        $key="tyz_mydefaulturlencryption";
    }
        $CI =& get_instance();
    $string = strtr(
            $string,
            array(
                '.' => '+',
                '-' => '=',
                '~' => '/'
            )
        );

    return $CI->encrypt->decode($string, $key);
}

STEP 2: Assign this file in autoload file

$autoload['helper'] = array('url','form','url_encryption_helper');

STEP 3: Call function encode_url in controller, model, view for encryption

   $rr="rahul K A";
   $a= encode_url($rr); 
Sign up to request clarification or add additional context in comments.

1 Comment

k a helped a lot thanks developers always be a developers
0

You can use a querystring:

<a href="<?php echo site_url('C_Name/M_Name/?id='.$this->encrypt->encode($id)); ?>">Link</a>

In a query string, you can use anything

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.