When uploading a file in PHP, which array key of the $_FILES superglobal gives the temporary location of the uploaded file?
- tmp_name
- name
- temp_location
- uploaded_file
The 'tmp_name' key in the $_FILES superglobal array contains the temporary location of the uploaded file on the server. This is important for processing and moving the file.
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.
You are developing a PHP script where you need to ensure that a particular value, say the company name, remains unchanged throughout the script. Which of the following would be the best approach?
- Define a constant
- Use a global variable
- Pass the value as a function parameter
- Store the value in a session variable
Defining a constant in PHP ensures that the value remains unchanged throughout the script, providing a read-only variable. This is suitable for constant values like company names.
Which of the following SQL statements is used to start a transaction in a relational database?
- BEGIN TRANSACTION
- INITIATE TRANSACTION
- START TRANSACTION
- CREATE TRANSACTION
The correct SQL statement to begin a transaction in a relational database is "BEGIN TRANSACTION." Starting a transaction is essential for ensuring data consistency.
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.