1. Question: How are session variables accessed?

    A
    Through $_GET

    B
    Through $_POS

    C
    Through $_REQUEST

    D
    Through global variables

    E
    None

    Note: Although session data can be accessed using the global variables if the register_globals INI setting is turned on, the exam uses a version of PHP configured using the default php.ini file found in the official PHP distribution. In recent versions of PHP, the register_globals setting is turned off by default because of its serious security implications. As a result, Answer E is correct.
    1. Report
  2. Question: What function causes the following header to be added to your server’s output?
    Set-Cookie: foo=bar;
    Your Answer: ______

    A
    header()

    B
    setcookie()

    C
    setrawcookie()

    D
    all

    E
    none

    Note: Clearly, this question refers to the setcookie or setrawcookie functions, although the header function could be used as well.
    1. Report
  3. Question: Under normal circumstances—and ignoring any browser bugs—how can a cookie be accessed from a domain other than the one it was set for?

    A
    By consulting the HTTP_REMOTE_COOKIE header

    B
    It cannot be done

    C
    By setting a different domain when calling setcookie()

    D
    By sending an additional request to the browser

    E
    By using Javascript to send the cookie as part of the URL

    Note: Answer B is correct. Browsers simply do not allow an HTTP transaction that takes place on one domain to set cookies for another domain. Doing otherwise would present clear security implications: for example, a malicious page on one domain could overwrite your session ID for another domain and force you to use another session to which a third party has access without your knowledge.
    1. Report
  4. Question: How can the index.php script access the email form element of the following HTML form? (Choose 2)
    <form action="index.php" method="post">
      <input type="text" name="email"/>
    </form>

    A
    $_GET['email']

    B
    $_POST['email']

    C
    $_SESSION['text’]

    D
    $_REQUEST['email']

    E
    $_POST['text']

    Note: Since the form’s method is post, the script will only be able to read the value through the $_POST and $_REQUEST superglobal arrays. The element’s name (email) is used as the key for the value in the array and, therefore, Answers B and D are correct. Note that, although perfectly valid from a logical perspective, the use of $_REQUEST should be discouraged because of potential security implications.
    1. Report
  5. Question: What will be the net effect of running the following script on the $s string? (Choose 2)
    <?php
      $s = '<p>Hello</p>';
      $ss = htmlentities ($s);
      echo $s;
    ?>

    A
    The string will become longer because the angular brackets will be converted to their HTML meta character equivalents

    B
    The string will remain unchanged

    C
    If the string is printed to a browser, the angular brackets will be visible

    D
    If the string is printed to a browser, the angular brackets will not be visible and it will be interpreted as HTML

    E
    The string is destroyed by the call to htmlentities()

    Note: This question tests nothing about your knowledge of HTML encoding—and everything about your ability to properly interpret code. The $s function is left unaltered by the call to htmlentities(), which returns the modified string so that it can be assigned to $ss. Therefore, Answers B and D are correct. If you’re wondering whether this is an unfair “trick” question, do keep in mind that, often, the ability to find and resolve bugs revolves around discovering little mistakes like this one.
    1. Report
  6. Question: If no expiration time is explicitly set for a cookie, what happens to it?

    A
    It expires right away

    B
    It never expires

    C
    It is not set

    D
    It expires at the end of the user’s browser session

    E
    It expires only if the script doesn’t create a server-side session

    Note: Cookies automatically expire at the end of the user’s browser session if no explicit expiration time is set. Cookies are not necessary to maintain a server-side session, so answer D is correct.
    1. Report
  7. Question: Consider the following form and subsequent script. What will the script print out if the user types the word “php” and “great” in the two text boxes respectively?
    <form action="index.php" method="post">
      <input type="text" name="element[]">
      <input type="text" name="element[]">
    </form>
    <?php
      echo $_GET['element'];
    ?>

    A
    Nothing

    B
    Array

    C
    A notice

    D
    phpgreat

    E
    greatphp

    Note: Since the form is submitted using a POST HTML transaction, whatever values are typed in the text boxes are only going to be available in the $_POST superglobal array. Therefore, Answer C is correct, since the $_GET array won’t contain any values and PHP will issue a notice to this effect.
    1. Report
  8. Question: In an HTTPS transaction, how are URLs and query strings passed from the browser to the web server?

    A
    They are passed in clear text, and the subsequent transaction is encrypted

    B
    They are encrypted

    C
    The URL is left in clear text, while the query string is encrypted

    D
    The URL is encrypted, while the query string is passed in clear text

    E
    To ensure its encryption, the query string is converted into a header and passed along with the POST information

    Note: When an HTTPS transaction takes place, the browser and the server immediately negotiate an encryption mechanism so that any subsequent data is not passed in clear text—including the URL and query string, which are otherwise passed the same way as with a traditional HTTP transaction. Answer B is, therefore, correct.
    1. Report
  9. Question: What happens when a form submitted to a PHP script contains two elements with the same name?

    A
    They are combined in an array and stored in the appropriate superglobal array

    B
    The value of the second element is added to the value of the first in the appropriate superglobal array

    C
    The value of the second element overwrites the value of the first in the appropriate superglobal array

    D
    The second element is automatically renamed

    E
    PHP outputs a warning

    Note: PHP simply adds elements to the appropriate superglobal array as they are retrieved from the query string or POST information. As a result, if two elements have the same name, the first one will just be overwritten by the second. Therefore, Answer C is correct.
    1. Report
  10. Question: How would you store an array in a cookie?

    A
    By adding two square brackets ([]) to the name of the cookie

    B
    By using the implode function

    C
    It is not possible to store an array in a cookie due to storage limitations

    D
    By using the serialize function

    E
    By adding the keyword ARRAY to the name of the cookie

    Note: Only Answer B is always correct. While the implode function can be used to convert an array into a string—a prerequisite of being able to store it in a cookie—it cannot guarantee that you’ll be able to reconstruct the array at a later date the way serialize() can. Storing an array in a cookie may not be a good idea because browsers only allow a limited amount of storage space for each cookie, but that’s not always the case—you should be able to store relatively small arrays without much in the way of problems.
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd