When developing a custom online shop in PHP, what are the key security measures that should be implemented to prevent hacking attempts?

To prevent hacking attempts on a custom online shop in PHP, key security measures that should be implemented include input validation to prevent SQL injection attacks, using prepared statements to prevent SQL injection and parameterized queries, implementing CSRF protection to prevent cross-site request forgery attacks, and using secure password hashing techniques to store user passwords.

// Input validation to prevent SQL injection
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);

// Prepared statements to prevent SQL injection
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();

// CSRF protection
session_start();
$token = bin2hex(random_bytes(32));
$_SESSION['csrf_token'] = $token;

// Secure password hashing
$options = [
    'cost' => 12,
];
$hashed_password = password_hash($password, PASSWORD_BCRYPT, $options);