To prevent session hijacking, it's a good practice to bind the session to the user's ________.
- IP Address
- Hardware Token
- Browser Fingerprint
- User Credentials
To prevent session hijacking, binding the session to the user's "Browser Fingerprint" is recommended. This involves tracking unique characteristics of the user's browser to ensure session continuity and security.
Which predefined PHP function can be used to reverse the order of the elements in an array?
- array_reverse()
- array_flip()
- array_rotate()
- array_shuffle()
The array_reverse() function is used to reverse the order of elements in an array. array_flip() flips the keys and values, while array_rotate() and array_shuffle() are not valid functions.
Imagine you're working on an e-commerce platform, and you need to format a number to two decimal places for displaying prices. Which of the following PHP functions would be most appropriate?
- number_format()
- round()
- floor()
- ceil()
The number_format() function is the most suitable for formatting numbers with two decimal places, making it ideal for displaying prices in an e-commerce context.
In PHP OOP, the concept of defining multiple methods with the same name but different parameters is called ________.
- Method Overloading
- Method Overriding
- Method Polymorphism
- Method Encapsulation
In PHP OOP, method overloading allows you to define multiple methods with the same name but different parameters, promoting code reusability.
What is the result of the expression 5%35%3 in PHP?
- 1
- 0
- 2
- 3
In PHP, the % operator is used for modulus. In this expression, 5%35 first results in 5, then 5%3 results in 2. So the answer is 2.
Using ________ ensures that even if two users have the same password, their hashed values will be different.
- Salted hashing
- Hash collision prevention
- Unique salting
- Hashed password variation
Utilizing salted hashing in password storage involves adding a unique random "salt" to each user's password before hashing it. This prevents identical passwords from having the same hashed value.
How can you differentiate between a 'directory' and a 'file' using PHP functions?
- is_dir() checks for directory
- file_exists() checks for a file
- scandir() lists the directory's contents
- is_file() checks for a file
The is_dir() function in PHP is used to determine if a given path is a directory. It's a key function for distinguishing directories from files.
When using PDO, which method fetches the next row from a result set?
- fetch()
- fetchNext()
- fetchRow()
- getNextRow()
The fetch() method in PDO is used to fetch the next row from a result set. It allows you to retrieve data from the result set one row at a time, facilitating efficient handling of large datasets.
To remove white spaces from the beginning and end of a string, you would use the ________ function in PHP.
- trim()
- remove_spaces()
- strip_whitespaces()
- clean_string()
The trim() function in PHP is used to remove white spaces from both the beginning and the end of a given string, making it useful for data cleaning.
Which of the following is a common best practice when writing PHP functions?
- Use global variables extensively
- Make functions as long as possible
- Provide meaningful function names
- Avoid using return statements inside
Giving functions meaningful names is essential for code readability and maintainability, a best practice in writing PHP functions.