This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “User Authentication”.
1. How many predefined variables does PHP use to authenticate a user?
a) 1
b) 2
c) 3
d) 4
View Answer
Explanation: 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)
View Answer
Explanation: $_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)
View Answer
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.
4. Which function is used to verify whether a variable contains a value?
a) header()
b) footer()
c) inset()
d) isset()
View Answer
Explanation: 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)
View Answer
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.
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
View Answer
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.
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
View Answer
Explanation: 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()
View Answer
Explanation: 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)
View Answer
Explanation: 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
View Answer
Explanation: It not only enhances administrative convenience and scalability but also can be integrated into a larger database infrastructure.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.
- Check PHP Books
- Apply for Programming Internship
- Check Information Technology Books
- Check MCA Books
- Practice Programming MCQs