PHP Questions and Answers - PHP User Authentication

1. Which function is used to remove all HTML tags from a string passed to a form?
a) remove_tags()
b) strip_tags()
c) tags_strip()
d) tags_remove()

  Discussion

Answer: b
Explanation: The function strip_tags() is used to strip a string from HTML, XML, and PHP tags.

2. What will be the value of the variable $input in the following PHP code?
<?php
$input = "Swapna<td>Lawrence</td>you are really<i>pretty</i>!";
$input = strip_tags($input,"<i></i>");
echo $input;
?>
a) Swapna Lawrence you are really pretty!
b) Swapna <td>Lawrence</td> you are really<i>pretty</i>!
c) Swapna <td>Lawrence</td> you are really pretty!
d) Swapna Lawrence you are really<i>pretty</i>!

  Discussion

Answer: d
Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially wreak havoc on a page.

3. To validate an email address, which flag is to be passed to the function filter_var()?
a) FILTER_VALIDATE_EMAIL
b) FILTER_VALIDATE_MAIL
c) VALIDATE_EMAIL
d) VALIDATE_MAIL

  Discussion

Answer: a
Explanation: The FILTER_VALIDATE_EMAIL is used to validates an e-mail address.

4. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?
a) 5
b) 6
c) 7
d) 8

  Discussion

Answer: c
Explanation: There are seven validation filters. They are FILTER_VALIDATE_EMAIL, FILTER_VALIDATE_BOOLEAN, FILTER_VALIDATE_FLOAT, FILTER_VALIDATE_INT, FILTER_VALIDATE_IP, FILTER_VALIDATE_REGEXP, FILTER_VALIDATE_URL.

5. How many predefined variables does PHP use to authenticate a user?
a) 1
b) 2
c) 3
d) 4

  Discussion

Answer: b
Explanation: The variables PHP use to authenticate a user are $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’].

6. Which of the following variables does PHP use to authenticate a user?
i) $_SERVER['PHP_AUTH_USER'].
ii) $_SERVER['PHP_AUTH_USERS'].
iii) $_SERVER['PHP_AUTH_PU'].
iv) $_SERVER['PHP_AUTH_PW'].
a) i) and ii)
b) ii) and iv)
c) i) and iv)
d) ii) and iii)

  Discussion

Answer: c
Explanation: $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’] store the username and password values, respectively.

7. Which of the following PHP function is commonly used when handling authentication via PHP?
i) header()
ii) footer()
iii) inset()
iv) isset()
a) i) and iv)
b) ii) and iv)
c) ii) and iii)
d) i) and iii)

  Discussion

Answer: a
Explanation: The function isset () is used to check whether a variable is set or not and the function header() sends a raw HTTP header to a client.

8. Which function is used to verify whether a variable contains a value?
a) header()
b) footer()
c) inset()
d) isset()

  Discussion

Answer: d
Explanation: The isset() function determines whether a variable has been assigned a value. Its prototype follows: boolean isset(mixed var [,mixed var [,…]]).

9. Which of the following are types of PHP authentication implementation methodologies?
i) Hard-coding a login pair directly into the script
ii) File-based authentication
iii) Data-based authentication
iv) PEAR'S HTTP authentication
a) ii) and iii)
b) i) and iv)
c) i), ii), iii) and iv)
d) Only iv)

  Discussion

Answer: c
Explanation: The method PEAR’S HTTP authentication is used to provides a framework for user authentication on the HTTP. The data-based authentication is the process of confirming that a user who is attempting to log in to a database is authorized to do so. In the file-based authentication as some small sites does not have a need for database back-end to store data, but security is still important either the site is big or small. They need to authenticate some folder or file and want to set access credentials for that. One can handle such by using file-based authentication using PHP. The simplest way to restrict resource access is by hard-coding the username and password directly into the script.

10. In which authentication method does changing the username or password can be done only by entering the code and making the manual adjustment.
a) Hard-coding a login pair directly into the script
b) File-based authentication
c) Data-based authentication
d) PEAR’S HTTP authentication

  Discussion

Answer: a
Explanation: The simplest way to restrict resource access is by hard-coding the username and password directly into the script. In this authentication method, changing the username or password can be done only by entering the code and making the manual adjustment. This is one of the drawbacks of hard-coding a login pair directly into the script.