CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: min(eight, nine)?
(Example: nine)

The Note You're Voting On

jefrey at forteras dot tech
7 years ago
NEVER USE this function to protect against SQL Injection.

It may sound ridiculous but I've seen a couple of developers doing so.

It's interesting that these developers use str_replace (let's ignore the fact that they don't even use the str_ireplace which is case-insensitive) to remove common SQL commands such as "SELECT" or "DROP" from user-entered inputs.

A funny thing to note is that:

<?php
$input
= "SELSELECTECT";
echo
str_replace("SELECT", null, $input); // = SELECT
?>

Yeah you could loop it, but str_replace was never meant to be used this way. There are proper ways to protect against SQL Injections, such as using prepared statements (placeholders).

<< Back to user notes page

To Top