简体   繁体   English

如何在CodeIgniter中生成字符串?

[英]How to generate a string in CodeIgniter?

I have to generate a string using the email id and current date. 我必须使用电子邮件ID和当前日期生成一个字符串。

This is for the purpose of providing an encrypted key to the user at the time of forgot password. 这是为了在忘记密码时向用户提供加密密钥。

How can I generate this? 我该如何生成?

i can't say this is the right thing, but you can try this 我不能说这是对的,但是你可以尝试一下

<?php
$this->load->library('encrypt');
$email  = "address@domain.com";
$date   = date(Y-m-d);

$string = $email."-".$date;
$encrypted_string = $this->encrypt->encode($string);
?>

to decode the string, use this 解码字符串,使用这个

<?php
$this->load->library('encrypt');
$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';
$string = $this->encrypt->decode($encrypted_string);
?>

You can generate string in Codigniter by using "encryption_key" in config file. 您可以通过在配置文件中使用“ encryption_key”在Codigniter中生成字符串。 You can easily generate encrypted string by following these steps. 您可以按照以下步骤轻松生成加密的字符串。

  1. Go to config.php file in config folder. 转到config文件夹中的config.php文件。 Find $config['encryption_key'] and set your encryption key. 找到$ config ['encryption_key']并设置您的加密密钥。 " !@#oiqjwd2131asda3ir0000wqe+_) " !## oiqjwd2131asda3ir0000wqe + _)
  2. Now go to your controller and call encryption class and generate your two variables $email, $date . 现在转到控制器并调用加密类,并生成两个变量$ email,$ date
  3. Concatenate those variables and pass them through encrypt() function OR you can pass them one by one (according to your need) and echo them. 连接这些变量,然后将它们通过crypto()函数传递,或者可以将它们一个接一个地传递(根据需要)并回显它们。
  4. Call the controller method and you will see your encrypted string. 调用controller方法,您将看到加密的字符串。
  5. You can also decrypt your string by using decrypt() function 您还可以通过使用crypto()函数解密字符串

Config.php config.php文件

$config['encryption_key'] =  "!@#oiqjwd2131asda3ir0000wqe+_)";

Tested code 经过测试的代码

    class trying extends CI_controller
    {
        public function index()
        {
            1. $this->load->library('encryption');
            2. $email  = "address@domain.com";
            3. $date   = date("Y/m/d");
            4. $string = $email.$date;
            5. echo $encrypted_string = $this->encryption->encrypt($string);
            6. echo "<br>".$decrypt = $this->encryption->decrypt($encrypted_string);
        }
    }

Now when you call the controller then by default index() method will call and then on line number 5 your your concatenated values will convert into encrypted form and on line number 6 your encrypted string will convert into original form. 现在,当您调用控制器时,默认情况下将调用index()方法,然后在第5行上,您的串联值将转换为加密形式,在第6行上,您的加密字符串将转换为原始形式。

Result 结果

Result will be something like this 结果将是这样的

efc080b13a0fc4d1d220c5dcecd87479eca3a2872fa349f0bbf7827a6652ba870bf1b877f83d3f81e33aa8ae8634d97696864224cbfba14c0a3ca2edb50205c4axQjvBYx93dTrN0ZBiJLQcAu+WzFmdIyMYqwxwkRyIlYvCOIRO4Qgec9Nz8Ds1Kn (encrypted form)

address@domain.com2017/11/13 (decrypted form)

I hope all this will help you a lot. 希望所有这些对您有很大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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