Imagine you are developing a PHP application that needs to frequently insert user data into a database. To ensure security and performance, which approach would be most appropriate?

  • Use PDO prepared statements
  • Use raw SQL statements with user input directly in the query
  • Use MySQLi extension with prepared statements
  • Use raw SQL statements with hardcoded values
Using PDO prepared statements is the recommended approach as it's secure against SQL injection and offers good performance.

To mitigate the risk of XSS attacks, developers should ________ any data that is output to the browser.

  • Escape
  • Encrypt
  • Validate
  • Sanitize
Developers should "Escape" any data that is output to the browser to protect against XSS (Cross-Site Scripting) attacks. Escaping ensures that user-generated content is displayed as plain text, preventing script execution.

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.

Given the PHP expression $a && $b, if $a is false, what can be said about the evaluation of $b?

  • $b will not be evaluated
  • $b will be evaluated
  • $b will always be false
  • $b will always be true
In a logical AND (&&) expression, if the left operand ($a) is false, PHP does not evaluate the right operand ($b). This is called "short-circuiting" and is useful for efficiency and avoiding errors.

When accepting user file uploads, one should never trust the file's ________ as it can be easily spoofed.

  • Extension
  • Size
  • Content-Type
  • Location
Trusting the file extension is risky, as attackers can easily change it. It's better to verify the file's content and use other security measures.

You have two arrays, one with keys and another with values. You need to combine them such that keys from the first array map to values from the second. Which PHP function would you use?

  • array_merge()
  • array_combine()
  • array_diff()
  • array_search()
The array_combine() function takes two arrays and creates a new array where the keys are from the first array and values from the second array.