Skip to content

Instantly share code, notes, and snippets.

@Bujhm
Created January 25, 2024 02:37
Show Gist options
  • Save Bujhm/08f65fb5bbca661ce0b680075930e596 to your computer and use it in GitHub Desktop.
Save Bujhm/08f65fb5bbca661ce0b680075930e596 to your computer and use it in GitHub Desktop.
security vulnerable php code (old)
<?php
// Code with the security issue
// Connect to the database
$mysqli = new mysqli ("localhost", "username", "password", "database");
// Check for errors
if ($mysqli->connect_error) {
die("Connection failed: ". $mysqli->connect_error);}
// Get the user input from a GET request
$user_id = $_GET['user_id'];
// SQL query
$sql = "SELECT username, email FROM users WHERE id = $user_id";
$result = $mysqli->query($sql);
// Fetch results
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "Username: " . $row["username"]. " - Email: " . $row["email"] . "<br> ";
}
} else {
echo "0 results";
}
$mysqli->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment