Features Flashcards

1
Q

How can you use PHP to send an “Authentication Required” box to the browser?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When using PHP to do browser-based authentication, what do you need to do to guarantee maximum compatibility?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does PHP determine if external authentication is in effect?

A

It uses the presence of the AuthType directive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you set cookies?

A

With setcookie() or setrawcookie().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When must setcookie() be called?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where are client cookies placed?

A

They are automatically included into a $_COOKIE auto-global array if variables_order contains “C”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you assign multiple values to a single cookie?

A

Just add [] to the cookie name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are XForms?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

With XForms, where is the browser-generated XML document stored?

A

$HTTP_RAW_POST_DATA

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When using XForms, how can you get your data loaded into the traditional $_POST variable?

A

Instruct the client browser to send it as application/x-www-form-urlencoded by changing the method attribute to urlencoded-post.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

From what can PHP receive file uploads?

A

Any RFC-1867 compliant browser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In a form, where can the MAX_FILE_SIZE hidden field be placed?

A

It must precede the file input field.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How reliable is the MAX_FILE_SIZE field?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What attribute do you need in a form for uploading files?

A

enctype=”multipart/form-data”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Where are uploaded files placed?

A

In the server’s default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can you set upload_tmp_dir with putenv()?

A

No; it won’t work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

If no file is selected for upload in your form, what will PHP return?

A

$_FILES[‘userfile’][‘size’] as 0, and $_FILES[‘userfile’][‘tmp_name’] as none.

18
Q

When is an uploaded file deleted from the temporary directory?

A

At the end of the request, if it has not been moved away or renamed.

19
Q

Where are file upload errors found?

A

$_FILES[‘userfile’][‘error’]

20
Q

What is the limit on MAX_FILE_SIZE?

A

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.

21
Q

What does max_execution_time affect?

A

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.

22
Q

What types of files may not be handled properly?

A

Files with exotic names (like those containing spaces).

23
Q

Can you mix normal input fields and file upload fields in the same form variable?

A

No.

24
Q

Can multiple files be uploaded simultaneously?

A

Yes. Just use the same array submission syntax in the HTML form as you do with multiple selects and checkboxes.

25
Q

How do you use the PUT method for uploading files?

A

First tell your webserver that you want a certain PHP script to handle the request (in Apache you do this with the Script directive).

26
Q

What do you need to do to be able to use HTTP and FTP urls with most of the functions that take a filename as a parameter?

A

Enable allow_furl_open in php.ini.

27
Q

Can you use urls with include, include_once, require, and require_once?

A

Yes.

28
Q

Can you overwrite an existing file on an FTP server with fopen?

A

No, but you can create new files.

29
Q

How do connect to FTP as a user other than anonymous?

A

You need to specify the username and password within the url (same syntax as for accessing files via HTTP when they require basic authentication).

30
Q

What are the 4 possible internal connection statuses in PHP?

A

0 - NORMAL
1 - ABORTED
2 - TIMEOUT
3 - ABORTED AND TIMEOUT

31
Q

When is the TIMEOUT state flag turned on?

A

When the PHP imposed time limit is hit.

32
Q

What is the default behavior for when a remote client disconnects from a PHP script?

A

The script enters ABORTED state. This behavior can be adjusted via the ignore_user_abort php.ini directive, or the ignore_user_abort Apache httpd.conf directive, or with the ignore_user_abort() function.

33
Q

What is the connection_aborted function?

A

It returns TRUE when a connection is aborted.

34
Q

What is the default timeout?

A

30 seconds. It can be changed using the max_execution_time php.ini directive, the max_execution Apache httpd.conf directive, or the set_time_limit() function.

35
Q

How can you check to see if a timeout caused a shutdown, within a shutdown function?

A

connection_status() will return a 2 if a timeout caused the shutdown function to be called.

36
Q

Can both the ABORTED and TIMEOUT states be active at the same time?

A

Yes. This is possible if you tell PHP to ignore user aborts.

37
Q

What are persistent database connections?

A

Database connections that don’t close when the execution of your script ends.

38
Q

Does PHP re-use persistent connections?

A

Yes. When a persistent connection is requested, PHP checks if there’s already an identical persistent connection, and if it exists, PHP uses it.

39
Q

What constitutes an “identical” PHP database connection?

A
  • opened on the same host
  • same username
  • same password
40
Q

What are the three ways in which your web server can utilize PHP to generate web pages?

A
  1. CGI wrapper. Run like this, an instance of the PHP interpreter is created and destroyed for every page request. So, persistent connections aren’t possible.
  2. Apache module. Persistent connections work here.
  3. Plugin for multithreaded web server. Persistent connections work here.
41
Q

What are persistent connections good for?

A

Efficiency. Reduced overhead when creating a link to the SQL server. If connection overhead is high, persistent connections help significantly.

42
Q

What are two caveats to keep in mind when using persistent connections?

A
  1. When using table locking on a persistent connection, if the script cannot release the lock, subsequent scripts using the same connection will block indefinitely.
  2. When using transactions, a transaction block will also carry over to the next script which uses that connection if script execution ends before the transaction block does.

You can use register_shutdown_function() to register a simple cleanup function to unlock your tables or roll back your transactions.