Jump to content

a function to real escape $_GET and $_POST !?


hassank1

Recommended Posts

I was thinking that instead of real escaping $_GET and $_POST each time manually.it's better to create a function that will be placed in (ex: global.php [called on each page]) which will contains a function that takes the $_POST and/or $_GET elements (if any) and real_escape_string them .. so is this a good idea or does it have disadvantages ?

 

and would u please help to implement this function that will loop every element and real_escape it ..

 

thx..

What I usually do is have all get and post variables as an array and submit that to a function which cleans the array and submits the array back.

 

<?php
private function cleandata($arr){
$cleanarr = array();
foreach($arr as $key => $value){
     $cleanarr [$key] = trim(mysql_real_escape_string($value));
}
        return $cleanarr;
}
?>

Just so you know, a really handy function for converting all the items return from that function into variables is the extract() function.  It'll convert all keys with their values to individual variables.

 

<?php
$data['name'] = "ted";
extract($data);
echo $name; // will display ted
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.