简体   繁体   中英

How to limit number of characters of encoded string in codeigniter

I'm sending an encoded value through URL, but I want to limit the number of characters after encryption using codeigniter's default encrypt library.

for eg:

echo $this->encrypt->encode("15532","key");

it returns like Pl5Qi0Q2tekcvW7q/cBdiGgKC7VHUA4kNdzUbGZAOZ/gGHcWjm860pefAEki/e+OE1cGhi+5gcMPduXl3Xwg0g==

How to reduce the length of this output. I know this is good, but i need this :(

It can be done by setting $this->_mcrypt_exists = FALSE; by extending encrypt library.

Any other good way to achieve this?

Setting $_mcrypt_exists to FALSE is a VERY, VERY, VERY BAD idea. Don't do that. It effectively means turning encryption off and using a basic encoding (but not encrypting) function instead.

CodeIgniter 2.2 was released because of that issue and it's Encrypt class now requires you to have MCrypt installed, it doesn't work without it.

On reducing the output: you simply can't do that safely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM