<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Using PHP</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="faq.build.html">Build Problems</a></div> <div class="next" style="text-align: right; float: right;"><a href="faq.passwords.html">Password Hashing</a></div> <div class="up"><a href="faq.html">FAQ</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="faq.using" class="chapter"> <h1>Using PHP</h1> <p class="para"> This section gathers many common errors that you may face while writing PHP scripts. </p> <div class="qandaset"><ol class="qandaset_questions"><li><a href="#faq.using.parameterorder"> I cannot remember the parameter order of PHP functions, are they random? </a></li><li><a href="#faq.using.anyform"> I would like to write a generic PHP script that can handle data coming from any form. How do I know which POST method variables are available? </a></li><li><a href="#faq.using.addslashes"> I need to convert all single-quotes (') to a backslash followed by a single-quote (\'). How can I do this with a regular expression? I'd also like to convert " to \" and \ to \\. </a></li><li><a href="#faq.using.stripslashes"> All my " turn into \" and my ' turn into \', how do I get rid of all these unwanted backslashes? How and why did they get there? </a></li><li><a href="#faq.register-globals"> How does the PHP directive register_globals affect me? </a></li><li><a href="#faq.using.wrong-order"> When I do the following, the output is printed in the wrong order: <?php function myfunc($argument) { echo $argument + 10; } $variable = 10; echo "myfunc($variable) = " . myfunc($variable); ?> what's going on? </a></li><li><a href="#faq.using.newlines"> Hey, what happened to my newlines? <pre> <?php echo "This should be the first line."; ?> <?php echo "This should show up after the new line above."; ?> </pre> </a></li><li><a href="#faq.using.headers-sent"> I get the message 'Warning: Cannot send session cookie - headers already sent...' or 'Cannot add header information - headers already sent...'. </a></li><li><a href="#faq.using.header"> I need to access information in the request header directly. How can I do this? </a></li><li><a href="#faq.using.authentication"> When I try to use authentication with IIS I get 'No Input file specified'. </a></li><li><a href="#faq.using.iis.sharing"> Windows: I can't access files shared on another computer using IIS </a></li><li><a href="#faq.using.mixml"> How am I supposed to mix XML and PHP? It complains about my <?xml tags! </a></li><li><a href="#faq.using.variables"> Where can I find a complete list of variables are available to me in PHP? </a></li><li><a href="#faq.using.freepdf"> How can I generate PDF files without using the non-free and commercial libraries like PDFLib? I'd like something that's free and doesn't require external PDF libraries. </a></li><li><a href="#faq.using.cgi-vars"> I'm trying to access one of the standard CGI variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined function, and it can't seem to find it. What's wrong? </a></li><li><a href="#faq.using.shorthandbytes"> A few PHP directives may also take on shorthand byte values, as opposed to only integer byte values. What are all the available shorthand byte options? And can I use these outside of php.ini? </a></li><li><a href="#faq.using.windowslocalhostissue"> Windows: I keep getting connection timeouts when using localhost, whereas "127.0.0.1" works? </a></li></ol></div> <dl class="qandaentry" id="faq.using.parameterorder"> <dt><strong> I cannot remember the parameter order of PHP functions, are they random? </strong></dt> <dd class="answer"> <p class="para"> PHP is a glue that brings together hundreds of external libraries, so sometimes this gets messy. However, a simple rule of thumb is as follows: </p> <p class="para"> <a href="book.array.html" class="link">Array function</a> parameters are ordered as "<em class="emphasis">needle, haystack</em>" whereas <a href="book.strings.html" class="link">String functions</a> are the opposite, so "<em class="emphasis">haystack, needle</em>". </p> </dd> </dl> <dl class="qandaentry" id="faq.using.anyform"> <dt><strong> I would like to write a generic PHP script that can handle data coming from any form. How do I know which POST method variables are available? </strong></dt> <dd class="answer"> <p class="para"> PHP offers many <a href="language.variables.predefined.html" class="link"> predefined variables</a>, like the superglobal <var class="varname"><var class="varname"> $_POST</var></var>. You may loop through <var class="varname"><var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var></var> as it's an associate array of all POSTed values. For example, let's simply loop through it with <a href="control-structures.foreach.html" class="link">foreach</a>, check for <span class="function"><a href="function.empty.html" class="function">empty()</a></span> values, and print them out. <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$empty </span><span style="color: #007700">= </span><span style="color: #0000BB">$post </span><span style="color: #007700">= array();<br />foreach (</span><span style="color: #0000BB">$_POST </span><span style="color: #007700">as </span><span style="color: #0000BB">$varname </span><span style="color: #007700">=> </span><span style="color: #0000BB">$varvalue</span><span style="color: #007700">) {<br /> if (empty(</span><span style="color: #0000BB">$varvalue</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$empty</span><span style="color: #007700">[</span><span style="color: #0000BB">$varname</span><span style="color: #007700">] = </span><span style="color: #0000BB">$varvalue</span><span style="color: #007700">;<br /> } else {<br /> </span><span style="color: #0000BB">$post</span><span style="color: #007700">[</span><span style="color: #0000BB">$varname</span><span style="color: #007700">] = </span><span style="color: #0000BB">$varvalue</span><span style="color: #007700">;<br /> }<br />}<br /><br />print </span><span style="color: #DD0000">"<pre>"</span><span style="color: #007700">;<br />if (empty(</span><span style="color: #0000BB">$empty</span><span style="color: #007700">)) {<br /> print </span><span style="color: #DD0000">"None of the POSTed values are empty, posted:\n"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$post</span><span style="color: #007700">);<br />} else {<br /> print </span><span style="color: #DD0000">"We have " </span><span style="color: #007700">. </span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$empty</span><span style="color: #007700">) . </span><span style="color: #DD0000">" empty values\n"</span><span style="color: #007700">;<br /> print </span><span style="color: #DD0000">"Posted:\n"</span><span style="color: #007700">; </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$post</span><span style="color: #007700">);<br /> print </span><span style="color: #DD0000">"Empty:\n"</span><span style="color: #007700">; </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$empty</span><span style="color: #007700">);<br /> exit;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <strong>Superglobals: availability note </strong><br /><p class="para">Superglobal arrays such as <var class="varname"><var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var></var>, and <var class="varname"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER</a></var></var>, etc. are available as of PHP 4.1.0. For more information, read the manual section on <a href="language.variables.predefined.html" class="link">superglobals</a></p></p></blockquote> </dd> </dl> <dl class="qandaentry" id="faq.using.addslashes"> <dt><strong> I need to convert all single-quotes (') to a backslash followed by a single-quote (\'). How can I do this with a regular expression? I'd also like to convert " to \" and \ to \\. </strong></dt> <dd class="answer"> <p class="para"> Assuming this is for a database, use the escaping mechanism that comes with the database. For example, use <span class="function"><a href="function.mysql-real-escape-string.html" class="function">mysql_real_escape_string()</a></span> with MySQL and <span class="function"><a href="function.pg-escape-string.html" class="function">pg_escape_string()</a></span> with PostgreSQL. There is also the generic <span class="function"><a href="function.addslashes.html" class="function">addslashes()</a></span> and <span class="function"><a href="function.stripslashes.html" class="function">stripslashes()</a></span> functions, that are more common with older PHP code. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <strong>directive note: magic_quotes_gpc </strong><br /><p class="para">The <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a> directive defaults to <em>on</em>. It essentially runs <span class="function"><a href="function.addslashes.html" class="function">addslashes()</a></span> on all GET, POST, and COOKIE data. <span class="function"><a href="function.stripslashes.html" class="function">stripslashes()</a></span> may be used to remove them.</p></p></blockquote> </dd> </dl> <dl class="qandaentry" id="faq.using.stripslashes"> <dt><strong> All my " turn into \" and my ' turn into \', how do I get rid of all these unwanted backslashes? How and why did they get there? </strong></dt> <dd class="answer"> <p class="para"> Most likely the backslashes magically exist because the PHP directive <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a> is on. This is an old feature of PHP, and should be disabled and not relied upon. Also, the PHP function <span class="function"><a href="function.stripslashes.html" class="function">stripslashes()</a></span> may be used to strip the backslashes from the <span class="type"><a href="language.types.string.html" class="type string">string</a></span>. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <strong>directive note: magic_quotes_gpc </strong><br /><p class="para">The <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a> directive defaults to <em>on</em>. It essentially runs <span class="function"><a href="function.addslashes.html" class="function">addslashes()</a></span> on all GET, POST, and COOKIE data. <span class="function"><a href="function.stripslashes.html" class="function">stripslashes()</a></span> may be used to remove them.</p></p></blockquote> </dd> </dl> <dl class="qandaentry" id="faq.register-globals"> <dt><strong> How does the PHP directive register_globals affect me? </strong></dt> <dd class="answer"> <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This feature has been <em class="emphasis">DEPRECATED</em> as of PHP 5.3.0 and <em class="emphasis">REMOVED</em> as of PHP 5.4.0.</p></div> <p class="para"> First, an explanation about what this ini setting does. Let's say the following URL is used: <em>http://example.com/foo.php?animal=cat</em> 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. 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 class="note"><p><strong class="note">Note</strong>: <p class="para"> 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"><var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var></var> was used. </p> </p></blockquote> </dd> </dl> <dl class="qandaentry" id="faq.using.wrong-order"> <dt><strong> 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(</span><span style="color: #0000BB">$variable</span><span style="color: #DD0000">) = " </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? </strong></dt> <dd class="answer"> <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 <span class="function"><a href="function.return.html" class="function">return</a></span> the value, not <span class="function"><a href="function.echo.html" class="function">echo</a></span> it. </p> </dd> </dl> <dl class="qandaentry" id="faq.using.newlines"> <dt><strong> 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> </strong></dt> <dd class="answer"> <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 class="qandaentry" id="faq.using.headers-sent"> <dt><strong> I get the message 'Warning: Cannot send session cookie - headers already sent...' or 'Cannot add header information - headers already sent...'. </strong></dt> <dd class="answer"> <p class="para"> The functions <span class="function"><a href="function.header.html" class="function">header()</a></span>, <span class="function"><a href="function.setcookie.html" class="function">setcookie()</a></span>, 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 <span class="function"><a href="function.headers-sent.html" class="function">headers_sent()</a></span> 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 class="qandaentry" id="faq.using.header"> <dt><strong> I need to access information in the request header directly. How can I do this? </strong></dt> <dd class="answer"> <p class="para"> The <span class="function"><a href="function.getallheaders.html" class="function">getallheaders()</a></span> 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[</span><span style="color: #0000BB">$name</span><span style="color: #DD0000">] = </span><span style="color: #0000BB">$content</span><span style="color: #DD0000"><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 <span class="function"><a href="function.apache-lookup-uri.html" class="function">apache_lookup_uri()</a></span>, <span class="function"><a href="function.apache-response-headers.html" class="function">apache_response_headers()</a></span>, and <span class="function"><a href="function.fsockopen.html" class="function">fsockopen()</a></span> </p> </dd> </dl> <dl class="qandaentry" id="faq.using.authentication"> <dt><strong> When I try to use authentication with IIS I get 'No Input file specified'. </strong></dt> <dd class="answer"> <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 affect 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 class="qandaentry" id="faq.using.iis.sharing"> <dt><strong> Windows: I can't access files shared on another computer using IIS </strong></dt> <dd class="answer"> <p class="para"> You have to change the <em>Go to Internet Information Services</em>. Locate your PHP file and go to its properties. Go to the <em>File Security</em> tab, <em>Edit -< Anonymous access and authentication control</em>. </p> <p class="para"> You can fix the problem either by unticking <em>Anonymous Access</em> and leaving <em>Integrated Window Authentication</em> ticked, or, by ticking <em>Anonymous Access</em> and editing the user as he may not have the access right. </p> </dd> </dl> <dl class="qandaentry" id="faq.using.mixml"> <dt><strong> How am I supposed to mix XML and PHP? It complains about my <?xml tags! </strong></dt> <dd class="answer"> <p class="para"> In order to embed <?xml straight into your PHP code, you'll have to turn off short tags by having the PHP directive <a href="ini.core.html#ini.short-open-tag" class="link">short_open_tags</a> set to <em>0</em>. You cannot set this directive with <span class="function"><a href="function.ini-set.html" class="function">ini_set()</a></span>. Regardless of <a href="ini.core.html#ini.short-open-tag" class="link">short_open_tags</a> being on or off, you can do something like: <em><?php echo '<?xml'; ?></em>. The default for this directive is <em>On</em>. </p> </dd> </dl> <dl class="qandaentry" id="faq.using.variables"> <dt><strong> Where can I find a complete list of variables are available to me in PHP? </strong></dt> <dd class="answer"> <p class="para"> Read the manual page on <a href="language.variables.predefined.html" class="link"> predefined variables</a> as it includes a partial list of predefined variables available to your script. A complete list of available variables (and much more information) can be seen by calling the <span class="function"><a href="function.phpinfo.html" class="function">phpinfo()</a></span> function. Be sure to read the manual section on <a href="language.variables.external.html" class="link">variables from outside of PHP</a> as it describes common scenarios for external variables, like from a HTML form, a Cookie, and the URL. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <strong>register_globals: important note</strong><br /><p class="para">As of PHP 4.2.0, the default value for the PHP directive <a href="ini.core.html#ini.register-globals" class="link">register_globals</a> is <em class="emphasis"> off</em>. The PHP community discourages developers from relying on this directive, and encourages the use of other means, such as the <a href="language.variables.predefined.html" class="link">superglobals</a>.</p></p></blockquote> </dd> </dl> <dl class="qandaentry" id="faq.using.freepdf"> <dt><strong> How can I generate PDF files without using the non-free and commercial libraries like <a href="ref.pdf.html" class="link">PDFLib</a>? I'd like something that's free and doesn't require external PDF libraries. </strong></dt> <dd class="answer"> <p class="para"> There are a few alternatives written in PHP such as <a href="http://www.fpdf.org/" class="link external">» FPDF</a> and <a href="http://www.tcpdf.org/" class="link external">» TCPDF</a>. </p> <p class="para"> There is also the <a href="book.haru.html" class="link">Haru</a> extension that uses the free libHaru external library. </p> </dd> </dl> <dl class="qandaentry" id="faq.using.cgi-vars"> <dt><strong> I'm trying to access one of the standard CGI variables (such as <var class="varname"><var class="varname">$DOCUMENT_ROOT</var></var> or <var class="varname"><var class="varname">$HTTP_REFERER</var></var>) in a user-defined function, and it can't seem to find it. What's wrong? </strong></dt> <dd class="answer"> <p class="para"> It's important to realize that the PHP directive <a href="ini.core.html#ini.register-globals" class="link">register_globals</a> also affects server and environment variables. When register_globals = off (the default is off since PHP 4.2.0), <var class="varname"><var class="varname">$DOCUMENT_ROOT</var></var> will not exist. Instead, use <var class="varname"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER['DOCUMENT_ROOT'] </a></var></var>. If register_globals = on then the variables <var class="varname"><var class="varname">$DOCUMENT_ROOT</var></var> and <var class="varname"><var class="varname"><a href="reserved.variables.globals.html" class="classname">$GLOBALS['DOCUMENT_ROOT']</a></var></var> will also exist. </p> <p class="para"> If you're sure register_globals = on and wonder why <var class="varname"><var class="varname">$DOCUMENT_ROOT</var></var> isn't available inside functions, it's because these are like any other variables and would require <em>global $DOCUMENT_ROOT</em> inside the function. See also the manual page on <a href="language.variables.scope.html" class="link">variable scope</a>. It's preferred to code with register_globals = off. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <strong>Superglobals: availability note </strong><br /><p class="para">Superglobal arrays such as <var class="varname"><var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var></var>, and <var class="varname"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER</a></var></var>, etc. are available as of PHP 4.1.0. For more information, read the manual section on <a href="language.variables.predefined.html" class="link">superglobals</a></p></p></blockquote> </dd> </dl> <dl class="qandaentry" id="faq.using.shorthandbytes"> <dt><strong> A few PHP directives may also take on shorthand byte values, as opposed to only <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> byte values. What are all the available shorthand byte options? And can I use these outside of <var class="filename">php.ini</var>? </strong></dt> <dd class="answer"> <p class="para"> The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes; available since PHP 5.1.0), these are case insensitive. Anything else assumes bytes. <em>1M</em> equals one Megabyte or <em>1048576</em> bytes. <em>1K</em> equals one Kilobyte or <em>1024</em> bytes. You may not use these shorthand notations outside of <var class="filename">php.ini</var>, instead use an <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> value of bytes. See the <span class="function"><a href="function.ini-get.html" class="function">ini_get()</a></span> documentation for an example on how to convert these values. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <strong>kilobyte versus kibibyte</strong><br /> <p class="para"> The PHP notation describes one kilobyte as equalling 1024 bytes, whereas the <acronym>IEC</acronym> standard considers this to be a kibibyte instead. Summary: k and K = 1024 bytes. </p> </p></blockquote> </dd> </dl> <dl class="qandaentry" id="faq.using.windowslocalhostissue"> <dt><strong> Windows: I keep getting connection timeouts when using <em>localhost</em>, whereas <em>"127.0.0.1"</em> works? </strong></dt> <dd class="answer"> <p class="para"> Prior to PHP 5.3.4, there was a bug in the network resolving code inside PHP that caused <em>localhost</em> in all stream related situations to fail if IPv6 was enabled. To work around this issue you can either use <em>"127.0.0.1"</em> or disable IPv6 resolving in the <var class="filename">hosts</var> file. </p> </dd> </dl> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="faq.build.html">Build Problems</a></div> <div class="next" style="text-align: right; float: right;"><a href="faq.passwords.html">Password Hashing</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>