我知道这可能看起来像这个问题重复:Ignore slash while using encryption in Codeigniter。但我仍然没有得到答案。
我想将加密的电子邮件名称作为URL发送到他们的电子邮件帐户。 然后解密该URL以搜索我的数据库中是否存在该电子邮件名称以允许该电子邮件进入我的系统。
问题是:
最后,我找到了一些库:Ignore Slash while using encryption in codeigniter - GitHub。
但它给了我这个错误:未定义的属性:CI_Loader :: $ my_encrypt
我不知道我做错了什么,我已经:
public function __construct() {parent::__construct();}
。$this->load->library('my_encrypt');
$this->my_encrypt->encode($key);
加载方法,这是给我一个错误的行。我知道这听起来像是一个简单的错误,但我也在使用另一个第三方库,但它根本没有给我一个错误。
任何人都可以帮我找到那里的错误/遗失步骤吗?
更新 - 在我在控制器中加载库之前,我想先查看结果。但即使我把代码放在控制器中,它也没有给我任何改变。这是代码:
$key = 'example@gmail.com';
$this->load->library('my_encrypt');
$segment = $this->my_encrypt->encode($key);
echo $segment;
echo ( $this->my_encrypt->decode($segment) );
更新: 修复库代码以使用CI_Encryption库进行扩展
答案 0 :(得分:3)
你加载了图书馆吗?在应用程序库中将librabry命名为MY_Encrypt.php
<?php
class MY_Encrypt extends CI_Encrypt
{
/**
* 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() {
parent::__construct();
}
function encode($string, $key="", $url_safe=TRUE)
{
$ret = parent::encode($string, $key);
if ($url_safe)
{
$ret = strtr(
$ret,
array(
'+' => '.',
'=' => '-',
'/' => '~'
)
);
}
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, $key="")
{
$string = strtr(
$string,
array(
'.' => '+',
'-' => '=',
'~' => '/'
)
);
return parent::decode($string, $key);
}
}
?>
现在调用加密库并使用加密类而不是my_encrypt
$key='Welcome';
$this->load->library('encrypt');
$key1= $this->encrypt->encode($key);
echo $key1;
答案 1 :(得分:2)
已修复以扩展CI_Encryption库,抱歉打扰。 :)
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() {
parent::__construct();
}
function encode($string)
{
$ret = parent::encrypt($string);
if ( !empty($string) )
{
$ret = strtr(
$ret,
array(
'+' => '.',
'=' => '-',
'/' => '~'
)
);
}
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(
$string,
array(
'.' => '+',
'-' => '=',
'~' => '/'
)
);
return parent::decrypt($string);
}
}
?>