You are building a web application that needs to process user-uploaded images. Which predefined PHP function can be used to get the width and height of an image?
- getimagesize()
- imagecreatefromjpeg()
- imagecopy()
- imagesetpixel()
The getimagesize() function in PHP is used to retrieve the width and height of an image, making it suitable for processing user-uploaded images.
You're developing an e-commerce site and want to store user cart items temporarily. Which would be the most appropriate method to store this data without requiring user login?
- Cookies
- Session Storage
- Local Storage
- IndexedDB
The most appropriate method for storing user cart items temporarily without requiring login would be "Session Storage." It's a client-side storage solution that retains data during a single session and is perfect for this use case.
Which of the following is a common security vulnerability that exploits web applications by injecting malicious SQL code?
- SQL Injection
- XSS (Cross-Site Scripting)
- CSRF (Cross-Site Request Forgery)
- Ransomware Attack
SQL Injection is a technique where an attacker injects malicious SQL code into input fields, potentially gaining unauthorized access to a database or system.
How can you modify the lifetime of a cookie in PHP?
- By setting the expires attribute in setcookie() function with a future timestamp.
- By using session_set_cookie_params()
- By directly modifying the cookie file.
- By changing the cookie name.
To modify the lifetime of a cookie in PHP, you can set the expires attribute in the setcookie() function with a future timestamp. This specifies when the cookie should expire.
Which PHP superglobal array contains information about uploaded files?
- $_GET
- $_POST
- $_FILES
- $_REQUEST
The $_FILES superglobal array in PHP contains information about uploaded files. It provides details such as file name, file type, and file size for files uploaded via a form.
Which of the following operators is used in PHP to check if two values are identical in both value and data type?
- ==
- ===
- =
- !=
The '===' operator in PHP checks for strict equality, meaning both the value and data type must match.
To ensure session data is only transferred over secure connections, you can enable the ________ configuration directive in PHP.
- session.use_trans_sid
- session.cookie_secure
- session.use_cookies
- session.use_only_cookies
The 'session.cookie_secure' configuration directive ensures that session cookies are only transmitted over secure (HTTPS) connections, enhancing 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.