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..

Link to comment
Share on other sites

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;
}
?>

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.