PHP Questions & Answers – User Authentication

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

Answer: b
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

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

3. Which of the following PHP function is commonly used when handling authentication via PHP?

i) header()
ii) footer()
iii) inset()
iv) isset()
Note: Join free Sanfoundry classes at Telegram or Youtube

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

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.

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

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

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

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.
advertisement

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

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.

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

Answer: b
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

Answer: c
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

Answer: c
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

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

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.