Challenge - 5 Problems
PHP Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this PHP code with SQL injection risk?
Consider this PHP code snippet that takes user input and queries a database. What will be the output if the input is
1 OR 1=1?PHP
<?php $user_input = "1 OR 1=1"; $query = "SELECT * FROM users WHERE id = $user_input"; echo $query; ?>
Attempts:
2 left
💡 Hint
Look at how the variable is inserted directly into the query string.
✗ Incorrect
The code directly inserts the user input without quotes or escaping, so the query becomes: SELECT * FROM users WHERE id = 1 OR 1=1, which can return all rows, showing SQL injection risk.
🧠 Conceptual
intermediate1:30remaining
Why is input validation important in PHP?
Which of the following best explains why input validation is critical in PHP applications?
Attempts:
2 left
💡 Hint
Think about what happens if bad data is accepted without checks.
✗ Incorrect
Input validation ensures that only safe and expected data is processed, preventing attacks like cross-site scripting or SQL injection.
🔧 Debug
advanced2:30remaining
Identify the security flaw in this PHP password handling code
What is the main security problem with this PHP code snippet for storing passwords?
PHP
<?php $password = $_POST['password']; $stored = md5($password); // Store $stored in database ?>
Attempts:
2 left
💡 Hint
Consider modern best practices for password hashing.
✗ Incorrect
MD5 is a fast hash and vulnerable to attacks. Modern PHP uses password_hash() for secure password storage.
📝 Syntax
advanced1:30remaining
What error does this PHP code produce?
What error will this PHP code cause?
PHP
<?php if(isset($_GET['id'])) { $id = $_GET['id']; $query = "SELECT * FROM users WHERE id = '$id"; // execute query } ?>
Attempts:
2 left
💡 Hint
Look carefully at the quotes inside the query string.
✗ Incorrect
The SQL query string is missing a closing single quote after $id, causing a syntax error in the query.
🚀 Application
expert3:00remaining
How many items are in the resulting array after this PHP code runs?
Given this PHP code that filters user input, how many items will be in the
$safe_inputs array?PHP
<?php $inputs = ['<script>', 'hello', '123', 'DROP TABLE users;', 'world']; $safe_inputs = array_filter($inputs, function($item) { return !preg_match('/<|>|DROP|TABLE/i', $item); }); echo count($safe_inputs); ?>
Attempts:
2 left
💡 Hint
Count how many items do NOT match the pattern.
✗ Incorrect
The items '