本文介绍了解密后无法读取变量和其他功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的加密应用程序,该应用程序可以使用此.我的问题是解密后,所有文件都无法像变量和函数那样工作.当我尝试回显变量时,它说未定义.

Im working on a simple encryption app that able to encrypt php files inside a folder using this class. My problem is after decryption, all the files are not working like the variables and the functions. When I tried to echo a variable its says undefined.

希望你能帮助我.

谢谢.

示例代码

<?php
    require_once('func.php');
    require_once('encryptionClass.php');
    if(is_array($_FILES)){

        $encrypted_dir = "encrypted_files/";
        $saveFiles = browseDir($encrypted_dir);

        foreach($saveFiles as $file){ // iterate files

        if(is_file($encrypted_dir.$file))

            unlink($encrypted_dir.$file); // delete file

        }

        foreach($_FILES['files']['name'] as $key => $value){

            $file = explode(".", $_FILES['files']['name'][$key]);
            $ext = array("php");

            if(in_array($file[1], $ext)){

                $file_name = $file[0].'.'.$file[1];
                $source = $_FILES['files']['tmp_name'][$key];
                $location = $encrypted_dir.$file_name;

                $code = file_get_contents($source);

                $encryption_key = 'CKXH2U9RPY3EFD70TLS1ZG4N8WQBOVI6AMJ5';
                $cryptor = new Cryptor($encryption_key);
                $crypted_token = $cryptor->encrypt($code);
                $f = fopen($location, 'w');

                // DATA BEING SAVE TO THE ENCRYPTED FILE

                $data = '
                    <?php

                        require_once("../encryptionClass.php");
                        $encryption_key = "CKXH2U9RPY3EFD70TLS1ZG4N8WQBOVI6AMJ5";
                        $cryptor = new Cryptor($encryption_key);
                        $crypted_token = "'. $crypted_token .'";
                        $token = $cryptor->decrypt($crypted_token);
                        echo $token;
                        ?>
                        <!-- trying to display the value of variable from $token -->
                        <p><?php echo $name; ?></p> 

                        ';


                fwrite($f, $data);
                fclose($f);
                unset($code);

            }
        }



    }
?>

推荐答案

解密后,解密后的代码以字符串的形式出现在 $ token 变量中.不是PHP代码,而是STRING.

After decrypting, your decrypted code is inside $token variable as a string. NOT PHP CODE, but STRING.

因此,您需要将 $ token 内容写入一个临时文件,并需要该文件才能像PHP代码那样访问它.

So, you need to write the $token content into a temporary file and require that file in order to access it like PHP Code.

希望您能理解

此外,您可以尝试使用 eval($ token)代替 echo $ token .这会将字符串评估为PHP代码.但是,这是非常不好的做法.

Also, you can give a try to eval($token) instead of echo $token. This will evaluate the string as PHP code. However, this is very bad practice.

这篇关于解密后无法读取变量和其他功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 04:41