faq/using.xml
0a3a57fae02391db80baeba98c9a071dc2760889
...
...
@@ -12,6 +12,7 @@
12
12
<qandaset>
13
13

14
14
<qandaentry xml:id="faq.using.parameterorder">
15
+
<!-- TODO: Mention named arguments -->
15
16
<question>
16
17
<para>
17
18
I cannot remember the parameter order of PHP functions, are they random?
...
...
@@ -41,8 +42,8 @@
41
42
<answer>
42
43
<para>
43
44
PHP offers many <link linkend="language.variables.predefined">
44
-
predefined variables</link>, like the superglobal <varname>
45
-
$_POST</varname>. You may loop through <varname>$_POST</varname>
45
+
predefined variables</link>, like the superglobal <varname>$_POST</varname>.
46
+
You may loop through <varname>$_POST</varname>
46
47
as it's an associate array of all POSTed values. For example, let's
47
48
simply loop through it with &foreach;,
48
49
check for <function>empty</function> values,
...
...
@@ -74,12 +75,11 @@ if (empty($empty)) {
74
75
</programlisting>
75
76
</para>
76
77

77
-
&note.superglobals;
78
-

79
78
</answer>
80
79
</qandaentry>
81
80

82
81
<qandaentry xml:id="faq.using.addslashes">
82
+
<!-- TODO Probably should mention not doing this... -->
83
83
<question>
84
84
<para>
85
85
I need to convert all single-quotes (') to a backslash
...
...
@@ -98,95 +98,9 @@ if (empty($empty)) {
98
98
<function>stripslashes</function> functions, that are more
99
99
common with older PHP code.
100
100
</para>
101
-

102
-
&note.magicquotes.gpc;
103
-

104
-
</answer>
105
-
</qandaentry>
106
-
107
-
<qandaentry xml:id="faq.using.stripslashes">
108
-
<question>
109
-
<para>
110
-
All my " turn into \" and my ' turn into \', how do I get rid of all
111
-
these unwanted backslashes? How and why did they get there?
112
-
</para>
113
-
</question>
114
-
<answer>
115
-
<para>
116
-
Most likely the backslashes magically exist because the PHP directive
117
-
<link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> is on.
118
-
This is an old feature of PHP, and should be disabled and not relied
119
-
upon. Also, the PHP function <function>stripslashes</function> may be
120
-
used to strip the backslashes from the <type>string</type>.
121
-
</para>
122
-
123
-
&note.magicquotes.gpc;
124
-
125
101
</answer>
126
102
</qandaentry>
127
103

128
-
<qandaentry xml:id="faq.register-globals">
129
-
<question>
130
-
<para>
131
-
How does the PHP directive register_globals affect me?
132
-
</para>
133
-
</question>
134
-
<answer>
135
-
&warn.deprecated.feature-5-3-0.removed-5-4-0;
136
-
<para>
137
-
First, an explanation about what this ini setting does. Let's say the
138
-
following URL is used:
139
-
<literal>http://example.com/foo.php?animal=cat</literal>
140
-
and in <filename>foo.php</filename> we might have the following
141
-
PHP code:
142
-
</para>
143
-
<para>
144
-
<programlisting role="php">
145
-
<![CDATA[
146
-
<?php
147
-
// Using $_GET here is preferred
148
-
echo $_GET['animal'];
149
-

150
-
// For $animal to exist, register_globals must be on
151
-
// DO NOT DO THIS
152
-
echo $animal;
153
-

154
-
// This applies to all variables, so $_SERVER too
155
-
echo $_SERVER['PHP_SELF'];
156
-

157
-
// Again, for $PHP_SELF to exist, register_globals must be on
158
-
// DO NOT DO THIS
159
-
echo $PHP_SELF;
160
-
?>
161
-
]]>
162
-
</programlisting>
163
-
</para>
164
-
<para>
165
-
The code above demonstrates how register_globals creates a lot of
166
-
variables. For years this type of coding has been frowned upon, and for
167
-
years it's been disabled by default. So although most web hosts disable
168
-
register_globals, there are still outdated articles, tutorials, and books
169
-
that require it to be on. Plan accordingly.
170
-
</para>
171
-
<para>
172
-
See also the following resources for additional information:
173
-
<simplelist>
174
-
<member>The <link linkend="ini.register-globals">register_globals</link> directive</member>
175
-
<member>The <link linkend="security.globals">security chapter about register globals</link></member>
176
-
<member><link linkend="language.variables.external">Handling external variables</link></member>
177
-
<member>Use <link linkend="language.variables.superglobals">superglobals</link> instead</member>
178
-
</simplelist>
179
-
</para>
180
-
<note>
181
-
<para>
182
-
In the example above, we used an <acronym>URL</acronym> that contained
183
-
a QUERY_STRING. Passing information like this is done through a GET HTTP
184
-
Request, so this is why the superglobal <varname>$_GET</varname> was used.
185
-
</para>
186
-
</note>
187
-
</answer>
188
-
</qandaentry>
189
-

190
104
<qandaentry xml:id="faq.using.wrong-order">
191
105
<question>
192
106
<para>
...
...
@@ -315,8 +229,8 @@ foreach ($headers as $name => $content) {
315
229
to create a plain HTML file (not parsed by PHP) as the entry page
316
230
into an authenticated directory. Then use a META tag to redirect
317
231
to the PHP page, or have a link to the PHP page. PHP will
318
-
then recognize the authentication correctly. With the ISAPI
319
-
module, this is not a problem. This should not affect other
232
+
then recognize the authentication correctly.
233
+
This should not affect other
320
234
NT web servers. For more information, see:
321
235
<link xlink:href="&url.iis;">&url.iis;</link> and the manual
322
236
section on <link linkend="features.http-auth">HTTP Authentication
...
...
@@ -387,9 +301,6 @@ foreach ($headers as $name => $content) {
387
301
outside of PHP</link> as it describes common scenarios for
388
302
external variables, like from a HTML form, a Cookie, and the URL.
389
303
</para>
390
-
391
-
&note.registerglobals;
392
-

393
304
</answer>
394
305
</qandaentry>
395
306

...
...
@@ -398,7 +309,7 @@ foreach ($headers as $name => $content) {
398
309
<para>
399
310
How can I generate PDF files without using the non-free and
400
311
commercial libraries like
401
-
<link linkend="ref.pdf">PDFLib</link>? I'd like something that's
312
+
PDFLib? I'd like something that's
402
313
free and doesn't require external PDF libraries.
403
314
</para>
404
315
</question>
...
...
@@ -408,45 +319,6 @@ foreach ($headers as $name => $content) {
408
319
<link xlink:href="&url.pdf.fpdf;">FPDF</link> and
409
320
<link xlink:href="&url.pdf.tcpdf;">TCPDF</link>.
410
321
</para>
411
-
<para>
412
-
There is also the <link linkend="book.haru">Haru</link> extension
413
-
that uses the free libHaru external library.
414
-
</para>
415
-
</answer>
416
-
</qandaentry>
417
-

418
-
<qandaentry xml:id="faq.using.cgi-vars">
419
-
<question>
420
-
<para>
421
-
I'm trying to access one of the standard CGI
422
-
variables (such as <varname>$DOCUMENT_ROOT</varname> or
423
-
<varname>$HTTP_REFERER</varname>) in a user-defined
424
-
function, and it can't seem to find it. What's wrong?
425
-
</para>
426
-
</question>
427
-
<answer>
428
-
<para>
429
-
It's important to realize that the PHP directive <link
430
-
linkend="ini.register-globals">register_globals</link> also affects
431
-
server and environment variables. When register_globals = off (the
432
-
default is off since PHP 4.2.0), <varname>$DOCUMENT_ROOT</varname>
433
-
will not exist. Instead, use <varname>$_SERVER['DOCUMENT_ROOT']
434
-
</varname>. If register_globals = on then the variables
435
-
<varname>$DOCUMENT_ROOT</varname> and
436
-
<varname>$GLOBALS['DOCUMENT_ROOT']</varname> will also exist.
437
-
</para>
438
-
<para>
439
-
If you're sure register_globals = on and wonder why
440
-
<varname>$DOCUMENT_ROOT</varname> isn't available inside functions,
441
-
it's because these are like any other variables and would
442
-
require <literal>global $DOCUMENT_ROOT</literal> inside the
443
-
function. See also the manual page on
444
-
<link linkend="language.variables.scope">variable scope</link>. It's
445
-
preferred to code with register_globals = off.
446
-
</para>
447
-
448
-
&note.superglobals;
449
-

450
322
</answer>
451
323
</qandaentry>
452
324

...
...
@@ -454,21 +326,20 @@ foreach ($headers as $name => $content) {
454
326
<question>
455
327
<para>
456
328
A few PHP directives may also take on shorthand byte values, as opposed
457
-
to only <type>integer</type> byte values. What are all the available
458
-
shorthand byte options? And can I use these outside of &php.ini;?
329
+
to only <type>int</type> byte values. What are all the available
330
+
shorthand byte options?
459
331
</para>
460
332
</question>
461
333
<answer>
462
334
<para>
463
335
The available options are K (for Kilobytes), M (for Megabytes) and G (for
464
-
Gigabytes; available since PHP 5.1.0), these are case insensitive.
465
-
Anything else assumes bytes.
466
-
<literal>1M</literal> equals one Megabyte or <literal>1048576</literal>
467
-
bytes. <literal>1K</literal> equals one Kilobyte or
468
-
<literal>1024</literal> bytes. You may not use these shorthand
469
-
notations outside of &php.ini;, instead use an <type>integer</type>
470
-
value of bytes. See the <function>ini_get</function> documentation for
471
-
an example on how to convert these values.
336
+
Gigabytes), and are all case-insensitive.
337
+
Anything else assumes bytes. <literal>1M</literal> equals one Megabyte or
338
+
<literal>1048576</literal> bytes. <literal>1K</literal> equals one
339
+
Kilobyte or <literal>1024</literal> bytes. These shorthand notations may
340
+
be used in &php.ini; and in the <function>ini_set</function> function.
341
+
Note that the numeric value is cast to <type>int</type>;
342
+
for instance, <literal>0.5M</literal> is interpreted as <literal>0</literal>.
472
343
</para>
473
344
<note>
474
345
<title>kilobyte versus kibibyte</title>
...
...
@@ -480,24 +351,6 @@ foreach ($headers as $name => $content) {
480
351
</note>
481
352
</answer>
482
353
</qandaentry>
483
-

484
-
<qandaentry xml:id="faq.using.windowslocalhostissue">
485
-
<question>
486
-
<para>
487
-
Windows: I keep getting connection timeouts when using <literal>localhost</literal>,
488
-
whereas <literal>"127.0.0.1"</literal> works?
489
-
</para>
490
-
</question>
491
-
<answer>
492
-
<para>
493
-
Prior to PHP 5.3.4, there was a bug in the network resolving code inside PHP that
494
-
caused <literal>localhost</literal> in all stream related situations to fail if IPv6
495
-
was enabled. To work around this issue you can either use <literal>"127.0.0.1"</literal>
496
-
or disable IPv6 resolving in the <filename>hosts</filename> file.
497
-
</para>
498
-
</answer>
499
-
</qandaentry>
500
-

501
354
</qandaset>
502
355
</chapter>
503
356

504
357