php变量可以安全地保存有害代码吗? [英] Can php variable hold harmfull code safely?
问题描述
假设我有一个文本文件。它包含有害代码,例如:
Let's say I have a text file. It contains "harmfull" code like:
<?php phpinfo(); ?>
也可以是其他任何内容,SQL注入代码,html链接等...
or it could be anything else, SQL injection code, html links etc...
现在这是我的示例脚本:
Now here is my example script:
$content = file_get_contents('harmfullcode.txt');
现在显然$ content变量将存储该有害代码。
Now obviously $content variable will store that harmfull code.
我的问题是,将这些信息存储在变量中是否安全?
My question is, is it safe to store such information in a variable?
例如,我知道我
echo $content;
然后它将是有害的。
但是,如果我对变量不执行任何操作,则变量可以安全地保存任何类型的有害代码吗?
But if I don't do anything with the variable, is it safe for the variable to hold any type of harmfull code?
编辑后使其更加清晰:
这有什么区别?
$content = file_get_contents('harmfullcode.txt');
$safevar = removebadstuff($content);
echo $safevar;
VS
$content = removebadstuff(file_get_contents('harmfullcode.txt'));
echo $content;
第二个示例在将不良内容分配给$ content之前将其删除...?我是php安全的新手,试图掌握这个概念。谢谢。
the second example removes bad stuff before assigning it to $content...?? I'm kind of new to php security, trying to grasp the concept. Thank you.
推荐答案
嘿,它们几乎是相同的。您可能想在第一个示例中取消设置
$ content
,因为第二个示例仅将局部变量创建为第一个参数 removebadstuff
。
hey are nearly identical. You might want to unset
$content
in the first example as the second example only creates the local variable as the first parameter of removebadstuff
.
请记住 PHP中的字符串是二进制安全的。
必读: 最终的清理/安全功能
这篇关于php变量可以安全地保存有害代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!