In the context of password hashing in PHP, what does "salting" mean?
- Adding salt to food
- Increasing the password length
- Mixing a unique value with the password
- Encrypting the password using SHA-256
"Salting" in password hashing involves mixing a unique value with the user's password before hashing to enhance security and prevent rainbow table attacks.
In the context of form validation, what does the term "sanitization" refer to?
- Removing malicious code
- Validating user credentials
- Cleaning and formatting data
- Authenticating the user
Sanitization in form validation involves cleaning and formatting user input data to remove harmful or unwanted characters, ensuring it's safe for processing.
Consider a scenario where you're building a CMS and you want to log errors to a specific file. Which PHP functions would be most suitable to open and write to this file?
- fopen() and fwrite()
- readfile() and copy()
- file_get_contents() and file_put_contents()
- file() and fwrite()
To open and write to a specific file in PHP, you should use fopen() to open the file and fwrite() to write to it. These functions offer fine-grained control over file handling, crucial for logging errors.
To ensure an uploaded file is not malicious, one should validate the file's ________ before saving it.
- File extension
- File size
- File name
- MIME type
The correct option is "MIME type." This is crucial because a file's MIME type provides information about its content, allowing you to verify that the uploaded file matches its claimed type and is not malicious.
Imagine you're building a feedback form where users can submit comments. To prevent potential script injections, which PHP function would you use to process the comment text before displaying it back to other users or saving it to a database?
- htmlentities()
- urlencode()
- strip_tags()
- base64_encode()
The htmlentities() function is used to convert potentially harmful characters in user input to their HTML entities, preventing script injections. It's a security measure to sanitize user-generated content.
Which type of JOIN returns only the rows where there is a match in both tables?
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN
An INNER JOIN returns only the rows where there is a match in both tables. It combines records from two tables based on a common column and includes only the rows with matching values in both tables. Rows with no matching values are excluded from the result set.
PHP provides a function named ________ to get the current date and time.
- current_datetime()
- time_now()
- date_time_now()
- date()
PHP's date() function is used to get the current date and time. It allows you to format the date and time in various ways as per your requirements.
Why is it recommended to avoid using the @ error suppression operator in PHP?
- It enhances code readability
- It prevents the error from occurring
- It improves error handling
- It makes code execute faster
The '@' operator suppresses error messages, making it hard to diagnose issues. It's best to handle errors explicitly for better debugging and code quality.
What is the primary difference between "overloading" and "overriding" in PHP OOP?
- Overloading is used to create multiple methods with the same name but different parameters.
- Overriding is used to create multiple methods with the same name but different parameters.
- Overloading allows you to define a new class that inherits from an existing class.
- Overriding allows you to create a new class that inherits from an existing class.
Overloading is about using the same method name with different parameters within the same class, while overriding is about providing a new implementation of a method in a child class.
In a multidimensional array, the ________ function can be used to count the total number of elements.
- count
- size
- total_elements
- array_length
To count the total number of elements in a multidimensional array, you can use the 'count' function in PHP. It counts all elements, including those within nested arrays.