duanhong8839 2017-12-19 19:54
浏览 295


I use the following code to generate a encrypted string for a given string.

class MY_class{
    public static function cryption($string){
        $output = base64_encode(openssl_encrypt($string, $cipher_method, $key, 0, $iv));
        $output = $iv . $output;
        return $output;

Using this code I generated the encrypted id of the id of a model object and replaced the original id.

$Model_object = Model_class::find(1);
$Model_object->id = MY_class::cryption($Model_object->id);
echo json_encode($Model_object);

For a given instance print_r() of $Model_object after replacing the original id with encrypted id gives me the following result.

[index] => Array
        [id] => 4df73f34cUYxVmVLWlFUU2M9

But json_encode() only outputs only the first decimal digits of the of the encrypted id.


I'd really appreciate if someone can explain why this is happening and how to overcome this problem.

P.S. I have already googled this problem and searched in Stack Overflow too. So, don't mention it in comments.

  • 写回答

1条回答 默认 最新

  • dpdfh60088 2017-12-19 21:37

    As @LSerni said, I was implicitly assigning the encrypted id which is a string to the integer property $Model_object->id.

    So I created a new dynamic property $Model_object->encrypted_id and assigned the encrypted id to it and called that property on the other side. It worked like a charm.

    Thank you very much @LSerni for your insight on the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥15 深海控制器DSE7320MKII和博世ECU间can通讯知识
    • ¥15 Ru的复折射率用于FDTD 200nm到1200nm
    • ¥15 使用Fiddler抓包,textview的乱码如何解决
    • ¥50 trio连接驱动器报错
    • ¥15 有谁懂nhanes的权重计算啊
    • ¥15 欧姆龙PLC 电机控制 限位
    • ¥30 如何处理shell命令接收到的视频流并实时播放出来
    • ¥15 虚心请教C#的代码优化问题
    • ¥15 有偿求做台风过境全过程模拟仿真
    • ¥50 求!AutomationDesk 如何自动导入Variant数据