250+ TOP MCQs on PHP User Authentication and Answers

PHP Multiple Choice Questions on “User Authentication”.

1. How many predefined variables does PHP use to authenticate a user?
a) 1
b) 2
c) 3
d) 4
Answer: b
Clarification: The variables PHP use to authenticate a user are $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’].

2. 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)
Answer: c
Clarification: $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’] store the username and password values, respectively.

3. 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)
Answer: a
Clarification: 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.

4. Which function is used to verify whether a variable contains a value?
a) header()
b) footer()
c) inset()
d) isset()
Answer: d
Clarification: The isset() function determines whether a variable has been assigned a value. Its prototype follows: boolean isset(mixed var [,mixed var [,…]]).

5. 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)
Answer: c
Clarification: 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.

  250+ TOP MCQs on PHP Uploading Files with PHP and Answers

6. 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
Answer: a
Clarification: 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.

7. The authenticationFile.txt, the file which stores username and password should be stored ___ the server document root.
a) Inside
b) Outside
c) Within
d) None of the mentioned
Answer: b
Clarification: If it is not stored outside, the attacker could discover the file through brute force guessing.

8. Which function is used to split a string into a series of substrings, with each string boundary is determined by a specific separator?
a) break()
b) divide()
c) explode()
d) md5()
Answer: c
Clarification: Although they are a similar function, you should use explode() instead of split(). In fact split() function has been deprecated altogether.

9. In which of the following situations does file-based authentication become inconvenient.

i) small list
ii) large number of user
iii) users are being regularly added
iv) static authentication

a) i) and iv)
b) i) and iii)
c) ii) and iii)
d) ii) and iv)

Answer: c
Clarification: Such requirements are better satisfied by implementing a database based solution.

10. Which is the most powerful authentication method among the four?
a) Hard-coding a login pair directly into the script
b) File-based authentication
c) Data-based authentication
d) PEAR’S HTTP authentication
Answer: c
Clarification: It not only enhances administrative convenience and scalability but also can be integrated into a larger database infrastructure.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top