faq.misc.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 187 行 · 第 1/2 页
HTML
187 行
php_manual_lang.tar. The tar format is known to be treated with most common archivers on Windows like e.g. <a href="http://www.winzip.com/" class="link external">» WinZip</a>. </p> </dd> </dl> <dl> <dt><strong> <p class="para"> What does & beside argument mean in function declaration of e.g. <a href="function.asort.html" class="function">asort()</a>? </p> </strong></dt> <dd><a name="faq.misc.arguments.references"></a> <p class="para"> It means that the argument is <a href="language.references.pass.html" class="link">passed by reference</a> and the function will likely modify it corresponding to the documentation. You can pass only variables this way and you don't need to pass them with & in function call (it's even <a href="ini.core.html#ini.allow-call-time-pass-reference" class="link">deprecated</a>). </p> </dd> </dl> <dl> <dt><strong> <p class="para"> How do I deal with <i>register_globals</i>? </p> </strong></dt> <dd><a name="faq.misc.registerglobals"></a> <p class="para"> For information about the security implications of <i>register_globals</i>, read the security chapter on <a href="security.globals.html" class="link">Using register_globals</a>. </p> <p class="para"> It's preferred to use <a href="language.variables.superglobals.html" class="link">superglobals</a>, rather than relying upon <i>register_globals</i> being on. </p> <p class="para"> If you are on a shared host with <i>register_globals</i> turned off and need to use some legacy applications, which require this option to be turned on, or you are on some hosting server, where this feature is turned on, but you would like to eliminate security risks, you might need to emulate the opposite setting with PHP. It is always a good idea to first ask if it would be possible to change the option somehow in PHP's configuration, but if it is not possible, then you can use these compatibility snippets. </p> <p class="para"> <div class="example"> <p><b>Example #1 Emulating Register Globals</b></p> <div class="example-contents"><p> This will emulate register_globals On. If you altered your <a href="ini.core.html#ini.variables-order" class="link">variables_order</a> directive, consider changing the <var class="varname">$superglobals</var> accordingly. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Emulate register_globals on<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'register_globals'</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$superglobals </span><span style="color: #007700">= array(</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">, </span><span style="color: #0000BB">$_ENV</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">, </span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">, </span><span style="color: #0000BB">$_POST</span><span style="color: #007700">, </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">);<br /> if (isset(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">array_unshift</span><span style="color: #007700">(</span><span style="color: #0000BB">$superglobals</span><span style="color: #007700">, </span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">);<br /> }<br /> foreach (</span><span style="color: #0000BB">$superglobals </span><span style="color: #007700">as </span><span style="color: #0000BB">$superglobal</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">extract</span><span style="color: #007700">(</span><span style="color: #0000BB">$superglobal</span><span style="color: #007700">, </span><span style="color: #0000BB">EXTR_SKIP</span><span style="color: #007700">);<br /> }<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p> This will emulate register_globals Off. Keep in mind, that this code should be called at the very beginning of your script, or after <a href="function.session-start.html" class="function">session_start()</a> if you use it to start your session. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Emulate register_globals off<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">unregister_GLOBALS</span><span style="color: #007700">()<br />{<br /> if (!</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'register_globals'</span><span style="color: #007700">)) {<br /> return;<br /> }<br /><br /> </span><span style="color: #FF8000">// Might want to change this perhaps to a nicer error<br /> </span><span style="color: #007700">if (isset(</span><span style="color: #0000BB">$_REQUEST</span><span style="color: #007700">[</span><span style="color: #DD0000">'GLOBALS'</span><span style="color: #007700">]) || isset(</span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">[</span><span style="color: #DD0000">'GLOBALS'</span><span style="color: #007700">])) {<br /> die(</span><span style="color: #DD0000">'GLOBALS overwrite attempt detected'</span><span style="color: #007700">);<br /> }<br /><br /> </span><span style="color: #FF8000">// Variables that shouldn't be unset<br /> </span><span style="color: #0000BB">$noUnset </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'GLOBALS'</span><span style="color: #007700">, </span><span style="color: #DD0000">'_GET'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'_POST'</span><span style="color: #007700">, </span><span style="color: #DD0000">'_COOKIE'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'_REQUEST'</span><span style="color: #007700">, </span><span style="color: #DD0000">'_SERVER'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'_ENV'</span><span style="color: #007700">, </span><span style="color: #DD0000">'_FILES'</span><span style="color: #007700">);<br /><br /> </span><span style="color: #0000BB">$input </span><span style="color: #007700">= </span><span style="color: #0000BB">array_merge</span><span style="color: #007700">(</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">, </span><span style="color: #0000BB">$_POST</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">, </span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">$_ENV</span><span style="color: #007700">, </span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">,<br /> isset(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">) && </span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">) ? </span><span style="color: #0000BB">$_SESSION </span><span style="color: #007700">: array());<br /> <br /> foreach (</span><span style="color: #0000BB">$input </span><span style="color: #007700">as </span><span style="color: #0000BB">$k </span><span style="color: #007700">=> </span><span style="color: #0000BB">$v</span><span style="color: #007700">) {<br /> if (!</span><span style="color: #0000BB">in_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$k</span><span style="color: #007700">, </span><span style="color: #0000BB">$noUnset</span><span style="color: #007700">) && isset(</span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #0000BB">$k</span><span style="color: #007700">])) {<br /> unset(</span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #0000BB">$k</span><span style="color: #007700">]);<br /> }<br /> }<br />}<br /><br /></span><span style="color: #0000BB">unregister_GLOBALS</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </dd> </dl> </div> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="faq.html">FAQ</a></div> <div class="next" style="text-align: right; float: right;"><a href="appendices.html">Appendices</a></div> <div class="up"><a href="faq.html">FAQ</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?