"Welcome to our PHP 101 blog, where we demystify the world of web development. "

Friday, August 16, 2024

MCQ-PHP's Role in Web Development

 MULTIPLE CHOICE QUESTIONS

PHP's Role in Web Development

1.     Which of the following is a reason PHP is often used in web development?
            a) It is a client-side language.
            b) It has built-in support for databases.
            c) It is used for designing web graphics.
            d) It provides static content only.

          Answer: b) It has built-in support for databases.

2.     Which server-side scripting language is commonly used with PHP for creating dynamic web pages?
a) Python
b) Ruby
c) JavaScript
d) None of the above

         Answer: d) None of the above (Correct answer: PHP itself is used, though  JavaScript is used for client-side scripting)

3.     What is one advantage of using PHP for server-side programming?
a) It can be embedded directly into HTML.
b) It is exclusively used for mobile app development.
c) It is not compatible with many databases.
d) It is slower compared to other server-side languages.

           Answer: a) It can be embedded directly into HTML.

4.     Which of the following is NOT a typical use case for PHP in web development?
a) Processing form data
b) Creating interactive web pages
c) Sending and receiving emails
d) Styling web pages with CSS

          Answer: d) Styling web pages with CSS

5.     Which of the following is an example of a web server that can run PHP?
a) Apache
b) Nginx
c) Microsoft IIS
d) All of the above

          Answer: d) All of the above

6.  Which function is used to retrieve the value of a specific HTTP header in PHP?
a) get_header()
b) header()
c) http_response_code()
d) apache_request_headers()

            Answer: d) apache_request_headers()

7.  Which PHP function is used to handle file uploads from a web form?
a) file_upload()
b) move_uploaded_file()
c) upload_file()
d) process_upload()

Answer: b) move_uploaded_file()

3.     Which of the following is a PHP superglobal array that holds information about HTTP headers, paths, and script locations?
a) $_SERVER
b) $_ENV
c) $_FILES
d) $_SESSION

Answer: a) $_SERVER

4.     What is the primary purpose of using PHP sessions in web development?
a) To handle form submissions
b) To store temporary data across multiple pages
c) To generate static HTML content
d) To manage database connections

Answer: b) To store temporary data across multiple pages

5.     Which of the following functions is used to execute an SQL query in PHP with prepared statements?
a) mysqli_prepare()
b) mysqli_query()
c) mysqli_execute()
d) mysqli_stmt()

Answer: a) mysqli_prepare()

1.     Which PHP function is used to sanitize input data to prevent SQL injection attacks?
a) filter_input()
b) mysqli_real_escape_string()
c) htmlspecialchars()
d) strip_tags()

Answer: b) mysqli_real_escape_string()

2.     Which of the following is NOT a common use case for PHP in web development?
a) Handling user authentication
b) Generating dynamic web content
c) Performing client-side form validation
d) Connecting to a database

Answer: c) Performing client-side form validation

3.     Which PHP function is used to start a session on a server?
a) session_start()
b) session_begin()
c) start_session()
d) begin_session()

Answer: a) session_start()

4.     Which PHP function can be used to send an HTTP response with a specific status code?
a) http_response_code()
b) send_status_code()
c) response_code()
d) header()

Answer: a) http_response_code()

5.     What is the primary purpose of PHP’s preg_match() function?
a) To search for a pattern in a string using regular expressions
b) To perform simple string replacements
c) To match strings to a specific length
d) To parse XML data

Answer: a) To search for a pattern in a string using regular expressions

1.     Which PHP function is used to securely hash passwords for storage?
a) md5()
b) sha1()
c) password_hash()
d) crypt()

Answer: c) password_hash()

2.     Which PHP function is used to safely escape HTML characters to prevent XSS attacks?
a) htmlspecialchars()
b) htmlentities()
c) strip_tags()
d) Both a and b

Answer: d) Both a and b

3.     What is the purpose of PHP’s mysqli_connect() function?
a) To execute SQL queries
b) To establish a connection to a MySQL database
c) To close a MySQL database connection
d) To retrieve data from a MySQL database

Answer: b) To establish a connection to a MySQL database

4.     Which of the following PHP functions would you use to handle JSON data?
a) json_encode()
b) json_decode()
c) json_parse()
d) Both a and b

Answer: d) Both a and b

5.     Which of the following PHP functions can be used to include a file only if it hasn’t been included before?
a) include_once()
b) require_once()
c) include()
d) require()

Answer: a) include_once()

1.     Which PHP function is used to connect to a PostgreSQL database?
a) pg_connect()
b) pg_query()
c) pg_close()
d) pg_exec()

Answer: a) pg_connect()

2.     Which PHP function allows you to execute an SQL statement with named placeholders?
a) mysqli_prepare()
b) mysqli_query()
c) mysqli_execute()
d) mysqli_stmt_bind_param()

Answer: a) mysqli_prepare()

3.     What is the purpose of PHP’s filter_var() function?
a) To validate and sanitize data
b) To handle file uploads
c) To manage sessions
d) To connect to a database

Answer: a) To validate and sanitize data

4.     Which PHP function is used to read the entire content of a file into a string?
a) file_get_contents()
b) file_read()
c) read_file()
d) file_content()

Answer: a) file_get_contents()

5.     Which PHP function is used to send an email?
a) mail()
b) sendmail()
c) email_send()
d) smtp_send()

Answer: a) mail()

1.     Which function in PHP is used to retrieve the value of a cookie?
a) get_cookie()
b) cookie_get()
c) $_COOKIE
d) retrieve_cookie()

Answer: c) $_COOKIE

2.     What is the primary use of the mysqli_real_escape_string() function in PHP?
a) To escape special characters in a SQL query
b) To encrypt data
c) To generate a random string
d) To compress a file

Answer: a) To escape special characters in a SQL query

3.     Which PHP function can be used to include a file and require that it exists, halting script execution if it doesn’t?
a) include()
b) require()
c) include_once()
d) require_once()

Answer: b) require()

4.     How can you send HTTP headers before any HTML content is sent to the browser?
a) By using header() function
b) By using http_response_code() function
c) By using set_header() function
d) By using send_header() function

Answer: a) By using header() function

5.     Which PHP function is used to delete a file?
a) delete_file()
b) unlink()
c) remove()
d) file_delete()

Answer: b) unlink()

No comments:

Post a Comment

Pages

SoraTemplates

Best Free and Premium Blogger Templates Provider.

Buy This Template