Which of the following functions in PHP is used to find the position of the first occurrence of a substring in a string?
- strpos()
- substr_position()
- find_string_position()
- locate_string_position()
The strpos() function in PHP is used to find the position of the first occurrence of a substring within a string.
The session data in PHP is stored by default in the ________ directory on the server.
- /tmp
- /var/sessions
- /sessions
- /session_data
In PHP, session data is, by default, stored in the /tmp directory on the server. Understanding where session data is stored is crucial for managing and securing user sessions in web applications.
Which function in PHP is used to make a connection to a MySQL database?
- mysqli_query
- mysql_connect
- mysqli_connect
- PDO::connect
The correct function is mysqli_connect. This function is used to establish a connection to a MySQL database in PHP using the MySQLi extension.
In PHP, the ________ function can be used to count the number of elements in an array, which can be useful when processing multiple form fields.
- array_count()
- count_array()
- elements_count()
- count()
In PHP, the 'count()' function is used to count the number of elements in an array, making it useful when processing multiple form fields as it helps you determine the array's size.
The PDO attribute that controls the error reporting mode is named ________.
- PDO::ERRMODE_SILENT
- PDO::ERRMODE_WARNING
- PDO::ERRMODE_EXCEPTION
- PDO::ERRMODE_ERRMODE
The PDO attribute that controls the error reporting mode is named PDO::ERRMODE_EXCEPTION, which makes PDO throw exceptions for errors.
What is the main reason for hashing passwords before storing them in a database?
- To make passwords case-insensitive
- To save storage space
- To improve password visibility
- To enhance security
Hashing passwords before storing them in a database enhances security. It ensures that the original password is not stored, making it much more difficult for attackers to retrieve user passwords in case of a breach.
What does XSS stand for in the context of web security?
- Cross-Site Scripting
- Extra Security System
- External System Security
- Excess Server Stress
XSS (Cross-Site Scripting) is a security vulnerability where attackers inject malicious scripts into web pages viewed by other users, compromising their data and privacy.
When handling multiple select fields in a form, the name attribute should end with ________ to ensure all selected values are sent to the server.
- '[]'
- '*'
- '+'
- 'multiple'
To ensure all selected values are sent to the server, the name attribute should end with '[]' for multiple select fields. This tells PHP to treat the data as an array.
What will the strpos() function return if the substring is not found in the string?
- -1
- 0
- FALSE
- Null
The strpos() function in PHP returns -1 when the substring is not found in the string. It's important to check for -1 to determine if the substring is absent.
Which of the following is NOT a valid way to return multiple values from a PHP function?
- Using an array
- Using a class with multiple properties
- Using a comma-separated string
- Using multiple return statements
While using a comma-separated string is technically possible, it's not a good practice for returning multiple values. The other options are valid approaches for returning multiple values.