Php 无斜杠的Codeigniter加密

Php 无斜杠的Codeigniter加密,php,codeigniter,Php,Codeigniter,我知道这看起来像是这个问题的重复:。但我仍然没有从中得到答案 我想将加密的电子邮件名称作为URL发送到他们的电子邮件帐户。 然后,该URL被解密以搜索我的数据库中是否存在该电子邮件名称,从而允许该电子邮件进入我的系统 问题是: 如果在加密后使用urlencode或base64_encode,则解密后搜索数据库时总是产生空值。我认为这是因为加密值总是在变化。 如果我使用临时加密,它可能有/字符。 如果我只使用编码,而不使用加密,它可能会允许电子邮件名称访问我的系统。 最后,我找到了一些库: 但它给

我知道这看起来像是这个问题的重复:。但我仍然没有从中得到答案

我想将加密的电子邮件名称作为URL发送到他们的电子邮件帐户。 然后,该URL被解密以搜索我的数据库中是否存在该电子邮件名称,从而允许该电子邮件进入我的系统

问题是:

如果在加密后使用urlencode或base64_encode,则解密后搜索数据库时总是产生空值。我认为这是因为加密值总是在变化。 如果我使用临时加密,它可能有/字符。 如果我只使用编码,而不使用加密,它可能会允许电子邮件名称访问我的系统。 最后,我找到了一些库:

但它给了我这个错误:未定义的属性:CI\u Loader::$my\u encrypt

$key='Welcome';
    $this->load->library('encrypt');
    $key1= $this->encrypt->encode($key);

    echo $key1;
我不知道我做错了什么,我已经:

将类名的第一个字母大写。 使用与类名相同的文件名。资本化 将扩展更改为CI_Encryption,因为Encrypt类已被弃用。 在所有方法之前插入公共函数_构造{parent::_构造;}。 将文件放在应用程序/库中。 加载库$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_加密库扩展的库代码

是否已加载库?在应用程序库中将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);
    }
}
?>

你载入图书馆了吗?在应用程序库中将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);
    }
}
?>

修复了扩展CI_加密库的问题,很抱歉打扰您:
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);
}
}
?>

修复了扩展CI_加密库的问题,很抱歉打扰您:
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);
}
}
?>

哎呀,在加载方法之前,我忘了告诉你我已经加载了库。问题编辑后,仍然有相同的错误。谢谢你的回答。哎呀,我忘了告诉你我在加载方法之前已经加载了库。问题编辑后,仍然有相同的错误。谢谢你的回答。