Q
Which PHP function is commonly used to sanitize input data from a form to prevent XSS attacks?

Answer & Solution

Answer: Option A
Solution:
The htmlspecialchars() function in PHP converts special characters to HTML entities, preventing XSS attacks by rendering injected scripts harmless.
Related Questions on Average

What security measure helps prevent form spamming by distinguishing between human users and bots?

A). CAPTCHA

B). HTTPS

C). CSRF Token

D). Two-Factor Authentication

Which PHP function is used to generate a random CSRF token for form submissions?

A). bin2hex()

B). uniqid()

C). md5()

D). openssl_random_pseudo_bytes()

Which PHP function is commonly used to check if a form field is empty?

A). empty()

B). isset()

C). is_empty()

D). is_null()

Which of the following is a secure method for storing passwords in a database?

A). Hashing

B). Encryption

C). Salting

D). All of the above

What security mechanism prevents Cross-Site Request Forgery (CSRF) attacks by generating and validating unique tokens for each form submission?

A). CSRF Token

B). Session Management

C). Secure Cookies

D). HTTPS

What does XSS stand for in the context of web security?

A). Cross-Site Scripting

B). XML Secure Socket

C). External Server Session

D). Cross-Site Sanitization

Which of the following is NOT a common input validation technique for form data?

A). Regular Expressions

B). Whitelisting

C). Blacklisting

D). Tokenization

What is the purpose of session management in web applications?

A). Maintaining User State

B). Encrypting Data

C). Preventing SQL Injection

D). Validating Form Data

What is the purpose of using HTTPS (HTTP Secure) in web applications?

A). Encrypting Data

B). Authenticating Users

C). Preventing XSS Attacks

D). Optimizing Page Load Speed

Which of the following is a best practice for preventing SQL Injection when executing SQL queries in PHP?

A). Use Parameterized Queries

B). Store Passwords in Plain Text

C). Use addslashes() Function

D). Disable Error Reporting