Home > Articles > Programming > PHP

  • Print
  • + Share This
  • 💬 Discuss
This chapter is from the book

Workshop

Quiz

  1. Which predefined variable could you use to determine the IP address of a user?

  2. Which predefined variable could you use to find out about the browser that called your script?

  3. What should you name your form fields to access their submitted values from an array variable called $form_array?

  4. Which built-in associative array contains all values submitted as part of a GET request?

  5. Which built-in associative array contains all values submitted as part of a POST request?

  6. What function would you use to redirect the browser to a new page? What string would you pass it?

  7. How can you limit the size of a file that a user can submit via a particular upload form?

  8. How can you set a limit to the size of upload files for all forms and scripts?

Quiz Answers

  1. The variable $REMOTE_ADDR should store the user's IP address.

  2. Browser type and version, as well as the user's operating system, are usually stored in a variable called $HTTP_USER_AGENT.

  3. Creating multiple fields with the name form_array[] creates a populated array called $form_array when the form is submitted.

  4. The built-in array $HTTP_GET_VARS contains all values submitted as part of a GET request.

  5. The built-in array $HTTP_POST_VARS contains all values submitted as part of a POST request.

  6. You can redirect a user by calling the header() function. You should pass it a Location header:

    header("Location: anotherpage.html");
  7. When creating upload forms in PHP 4, you can include a hidden field called MAX_FILE_SIZE:

  8. <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="51200">
  9. The php.ini option upload_max_filesize determines the maximum size of an upload file that any script will accept. This is set to 2 megabytes by default.

Activities

  1. Create a calculator script that allows the user to submit two numbers and choose an operation to perform on them (addition, multiplication, division, subtraction).

  2. Use hidden fields with the script you created in activity 1 to store and display the number of requests that the user has submitted.

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus