note 97301 deleted from function.mysql-real-escape-string by degeberg

From: Date: Tue, 13 Apr 2010 09:40:57 +0000
Subject: note 97301 deleted from function.mysql-real-escape-string by degeberg
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168191@lists.php.net to get a copy of this message
Note Submitter: the-day-that-never-comes at hotmail dot co dot uk Reason: bad code ---- This function can be changed to be suited for; $_GET, $_POST, $_SERVER, $_SESSION, $_COOKIE and others. However.. your return can only be 1 variable. So if you use $_GET //AND// $_POST, your return will be for ex: $array This will.. make a mess of things. This function is set for $_POST. I know this function can be changed, though I'm just a beginner :) <?php function clean($_POST, $a, $b) { if($a == '1') : $_POST = array_map('trim', $_POST); endif; if(get_magic_quotes_gpc()) : $_POST = array_map('stripslashes', $_POST); endif; $_POST = array_map('mysql_real_escape_string', $_POST); if($b == '1') : $_POST = array_map('ucwords', $_POST); return $_POST; endif; if($b == '2') : $_POST = array_map('strtolower', $_POST); return $_POST; endif; if($b == '3') : $_POST = array_map('strtoupper', $_POST); return $_POST; endif; } ?> The usage of this function, can be similar to this. <?php clean($_POST, 1, 1); ?> This will do a clean process of.. <?php ucwords(mysql_real_escape_string(trim($_POST))); ?> With stripslashes if the get_magic_quotes_gpc() if statement returns true.

« previous php.notes (#168191) next »