📄 faq.using.html
字号:
</b><br />The <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a>directive defaults to <i>on</i>. It essentially runs<a href="function.addslashes.html" class="function">addslashes()</a> on all GET, POST, and COOKIE data.<a href="function.stripslashes.html" class="function">stripslashes()</a> may be used to remove them.<br /></p></blockquote> </dd> </dl> <dl> <dt><strong> <p class="para"> How does the PHP directive register_globals affect me? </p> </strong></dt> <dd><a name="faq.register-globals"></a> <p class="para"> First, an explanation about what this ini setting does. Let's say the following URL is used: <i>http://example.com/foo.php?animal=cat</i> and in <var class="filename">foo.php</var> we might have the following PHP code: </p> <p class="para"> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Using $_GET here is preferred<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'animal'</span><span style="color: #007700">];<br /><br /></span><span style="color: #FF8000">// For $animal to exist, register_globals must be on<br />// DO NOT DO THIS<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$animal</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// This applies to all variables, so $_SERVER too<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'PHP_SELF'</span><span style="color: #007700">];<br /><br /></span><span style="color: #FF8000">// Again, for $PHP_SELF to exist, register_globals must be on<br />// DO NOT DO THIS<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$PHP_SELF</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </p> <p class="para"> The code above demonstrates how register_globals creates a lot of variables. For years this type of coding has been frowned upon, and for years it's been disabled by default. Note that PHP 6 removes this deprecated feature. So although most web hosts disable register_globals, there are still outdated articles, tutorials, and books that require it to be on. Plan accordingly. </p> <p class="para"> See also the following resources for additional information: <ul class="simplelist"> <li class="member">The <a href="ini.core.html#ini.register-globals" class="link">register_globals</a> directive</li> <li class="member">The <a href="security.globals.html" class="link">security chapter about register globals</a></li> <li class="member"><a href="language.variables.external.html" class="link">Handling external variables</a></li> <li class="member">Use <a href="language.variables.superglobals.html" class="link">superglobals</a> instead</li> </ul> </p> <blockquote><p><b class="note">Note</b>: In the example above, we used an <acronym title="Uniform Resource Locator">URL</acronym> that contained a QUERY_STRING. Passing information like this is done through a GET HTTP Request, so this is why the superglobal <var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var> was used. <br /> </p></blockquote> </dd> </dl> <dl> <dt><strong> <p class="para"> When I do the following, the output is printed in the wrong order: <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">myfunc</span><span style="color: #007700">(</span><span style="color: #0000BB">$argument</span><span style="color: #007700">)<br />{<br /> echo </span><span style="color: #0000BB">$argument </span><span style="color: #007700">+ </span><span style="color: #0000BB">10</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$variable </span><span style="color: #007700">= </span><span style="color: #0000BB">10</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"myfunc($variable) = " </span><span style="color: #007700">. </span><span style="color: #0000BB">myfunc</span><span style="color: #007700">(</span><span style="color: #0000BB">$variable</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> what's going on? </p> </strong></dt> <dd><a name="faq.using.wrong-order"></a> <p class="para"> To be able to use the results of your function in an expression (such as concatenating it with other strings in the example above), you need to <b>return()</b> the value, not <a href="function.echo.html" class="function">echo()</a> it. </p> </dd> </dl> <dl> <dt><strong> <p class="para"> Hey, what happened to my newlines? <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><pre><br /><span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">"This should be the first line."</span><span style="color: #007700">; </span><span style="color: #0000BB">?><br /><?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">"This should show up after the new line above."</span><span style="color: #007700">; </span><span style="color: #0000BB">?><br /></span></pre></span></code></div> </div> </p> </strong></dt> <dd><a name="faq.using.newlines"></a> <p class="para"> In PHP, the ending for a block of code is either "?>" or "?>\n" (where \n means a newline). So in the example above, the echoed sentences will be on one line, because PHP omits the newlines after the block ending. This means that you need to insert an extra newline after each block of PHP code to make it print out one newline. </p> <p class="para"> Why does PHP do this? Because when formatting normal HTML, this usually makes your life easier because you don't want that newline, but you'd have to create extremely long lines or otherwise make the raw page source unreadable to achieve that effect. </p> </dd> </dl> <dl> <dt><strong> <p class="para"> I get the message 'Warning: Cannot send session cookie - headers already sent...' or 'Cannot add header information - headers already sent...'. </p> </strong></dt> <dd><a name="faq.using.headers-sent"></a> <p class="para"> The functions <a href="function.header.html" class="function">header()</a>, <a href="function.setcookie.html" class="function">setcookie()</a>, and the <a href="ref.session.html" class="link">session functions</a> need to add headers to the output stream but headers can only be sent before all other content. There can be no output before using these functions, output such as HTML. The function <b> headers_sent()</b> will check if your script has already sent headers and see also the <a href="ref.outcontrol.html" class="link">Output Control functions</a>. </p> </dd> </dl> <dl> <dt><strong> <p class="para"> I need to access information in the request header directly. How can I do this? </p> </strong></dt> <dd><a name="faq.using.header"></a> <p class="para"> The <a href="function.getallheaders.html" class="function">getallheaders()</a> function will do this if you are running PHP as an Apache module. So, the following bit of code will show you all the request headers: <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$headers </span><span style="color: #007700">= </span><span style="color: #0000BB">getallheaders</span><span style="color: #007700">();<br />foreach (</span><span style="color: #0000BB">$headers </span><span style="color: #007700">as </span><span style="color: #0000BB">$name </span><span style="color: #007700">=> </span><span style="color: #0000BB">$content</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"headers[$name] = $content<br />\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </p> <p class="para"> See also <a href="function.apache-lookup-uri.html" class="function">apache_lookup_uri()</a>, <a href="function.apache-response-headers.html" class="function">apache_response_headers()</a>, and <a href="function.fsockopen.html" class="function">fsockopen()</a> </p> </dd> </dl> <dl> <dt><strong> <p class="para"> When I try to use authentication with IIS I get 'No Input file specified'. </p> </strong></dt> <dd><a name="faq.using.authentication"></a> <p class="para"> The security model of IIS is at fault here. This is a problem common to all CGI programs running under IIS. A workaround is to create a plain HTML file (not parsed by PHP) as the entry page into an authenticated directory. Then use a META tag to redirect to the PHP page, or have a link to the PHP page. PHP will then recognize the authentication correctly. With the ISAPI module, this is not a problem. This should not effect other NT web servers. For more information, see: <a href="http://support.microsoft.com/kb/q160422/" class="link external">» http://support.microsoft.com/kb/q160422/</a> and the manual section on <a href="features.http-auth.html" class="link">HTTP Authentication </a>. </p> </dd> </dl> <dl> <dt><strong> <p class="para"> Windows: I can't access files shared on another computer using IIS </p> </strong></dt> <dd><a name="faq.using.iis.sharing"></a> <p class="para"> You have to change the <i>Go to Internet Information Services</i>. Locate your PHP file and go to its properties. Go to the <i>File Security</i> tab, <i>Edit -< Anonymous access and authentication control</i>. </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -