Features Flashcards
How can you use PHP to send an “Authentication Required” box to the browser?
Use the header() function. The username, password, and authentication type will be placed in PHP_AUTH_USER, PHP_AUTH_PW, and AUTH_TYPE, in the $_SERVER AND $HTTP_SERVER_VARS arrays. Both basic and digest authentication methods are supported.
When using PHP to do browser-based authentication, what do you need to do to guarantee maximum compatibility?
The keyword “Basic” should be written with an uppercase “B”, the realm string must be enclosed in double quotes (not single), and exactly one space should precede the 401 code in the HTTP/1.0 401 header line. For buggy IE browsers, send the WWW-Authenticate header before the HTTP/4.01 header.
How does PHP determine if external authentication is in effect?
It uses the presence of the AuthType directive.
How can you set cookies?
With setcookie() or setrawcookie().
When must setcookie() be called?
Before any output is sent to the browser (the same limitation that header() has). You can use the output buffering functions to delay the script output until you have decided whether or not to set any cookies or send any headers.
Where are client cookies placed?
They are automatically included into a $_COOKIE auto-global array if variables_order contains “C”.
How can you assign multiple values to a single cookie?
Just add [] to the cookie name.
What are XForms?
They’re a variation on traditional webforms which allow them to be used on a wider variety of platforms. The form details are sent as XML formatted data.
With XForms, where is the browser-generated XML document stored?
$HTTP_RAW_POST_DATA
When using XForms, how can you get your data loaded into the traditional $_POST variable?
Instruct the client browser to send it as application/x-www-form-urlencoded by changing the method attribute to urlencoded-post.
From what can PHP receive file uploads?
Any RFC-1867 compliant browser.
In a form, where can the MAX_FILE_SIZE hidden field be placed?
It must precede the file input field.
How reliable is the MAX_FILE_SIZE field?
Not at all. It’s simply a convenience feature to notify the user prior to attempting to transfer a large file. It’s easy to fool on the browser side.
What attribute do you need in a form for uploading files?
enctype=”multipart/form-data”
Where are uploaded files placed?
In the server’s default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini.
Can you set upload_tmp_dir with putenv()?
No; it won’t work.
If no file is selected for upload in your form, what will PHP return?
$_FILES[‘userfile’][‘size’] as 0, and $_FILES[‘userfile’][‘tmp_name’] as none.
When is an uploaded file deleted from the temporary directory?
At the end of the request, if it has not been moved away or renamed.
Where are file upload errors found?
$_FILES[‘userfile’][‘error’]
What is the limit on MAX_FILE_SIZE?
It cannot specify a file size greater than the file size that has been set in the upload_max_filesize directive in php.ini. The default is 2 megabytes. memory_limit must also be set large enough, as well as max_execution_time, post_max_size, and max_file_uploads.
What does max_execution_time affect?
Only the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), the sleep() function, database queries, time taken by the file upload process, etc. is not included.
What types of files may not be handled properly?
Files with exotic names (like those containing spaces).
Can you mix normal input fields and file upload fields in the same form variable?
No.
Can multiple files be uploaded simultaneously?
Yes. Just use the same array submission syntax in the HTML form as you do with multiple selects and checkboxes.