security.variables.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 88 行

HTML
88
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>User Submitted Data</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="security.globals.html">Using Register Globals</a></div> <div class="next" style="text-align: right; float: right;"><a href="security.magicquotes.html">Magic Quotes</a></div> <div class="up"><a href="security.html">Security</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1>User Submitted Data</h1> <p class="para">  The greatest weakness in many PHP programs is not inherent in the  language itself, but merely an issue of code not being written with  security in mind. For this reason, you should always take the time  to consider the implications of a given piece of code, to ascertain  the possible damage if an unexpected variable is submitted to it.  <div class="example">   <p><b>Example #1 Dangerous Variable Usage</b></p>   <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;remove&nbsp;a&nbsp;file&nbsp;from&nbsp;the&nbsp;user's&nbsp;home&nbsp;directory...&nbsp;or&nbsp;maybe<br />//&nbsp;somebody&nbsp;else's?<br /></span><span style="color: #0000BB">unlink&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$evil_var</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Write&nbsp;logging&nbsp;of&nbsp;their&nbsp;access...&nbsp;or&nbsp;maybe&nbsp;an&nbsp;/etc/passwd&nbsp;entry?<br /></span><span style="color: #0000BB">fwrite&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$evil_var</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Execute&nbsp;something&nbsp;trivial..&nbsp;or&nbsp;rm&nbsp;-rf&nbsp;*?<br /></span><span style="color: #0000BB">system&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$evil_var</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">exec&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$evil_var</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>   </div>  </div> </p> <p class="para">  You should always carefully examine your code to make sure that any  variables being submitted from a web browser are being properly  checked, and ask yourself the following questions:  <ul class="itemizedlist">   <li class="listitem">    <span class="simpara">     Will this script only affect the intended files?    </span>   </li>   <li class="listitem">    <span class="simpara">     Can unusual or undesirable data be acted upon?    </span>   </li>   <li class="listitem">   <span class="simpara">     Can this script be used in unintended ways?    </span>   </li>   <li class="listitem">    <span class="simpara">     Can this be used in conjunction with other scripts in a negative     manner?    </span>   </li>   <li class="listitem">    <span class="simpara">     Will any transactions be adequately logged?    </span>   </li>  </ul> </p> <p class="para">  By adequately asking these questions while writing the script,  rather than later, you prevent an unfortunate re-write when you  need to increase your security. By starting out with this mindset,  you won&#039;t guarantee the security of your system, but you can help  improve it. </p> <p class="para">  You may also want to consider turning off register_globals,  magic_quotes, or other convenience settings which may confuse  you as to the validity, source, or value of a given variable.  Working with PHP in error_reporting(E_ALL) mode can also help warn  you about variables being used before they are checked or  initialized (so you can prevent unusual data from being  operated upon). </p></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="security.globals.html">Using Register Globals</a></div> <div class="next" style="text-align: right; float: right;"><a href="security.magicquotes.html">Magic Quotes</a></div> <div class="up"><a href="security.html">Security</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?