TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-25-2010, 08:50 AM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default Data Cleanse of $_REQUEST array

Hi - i'm pulling all input to drive my site from the php $_REQUEST variable and to protect my site from malicious input i want to find a neat way to loop through the $_REQUEST array and cleanse it probably by running a mysql function to remove injection code and also a php strip tags routine. How can i do this and repopulate each REQUEST parameter when i wont necessarily know what variables are set eg. sometimes it might be $_REQUEST['username'] sometimes other stuff but different depending on which command i am processing. Any ideas? Thanks.
captainmerton is offline  
Reply With Quote
Old 11-25-2010, 06:33 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by captainmerton View Post
Hi - i'm pulling all input to drive my site from the php $_REQUEST variable and to protect my site from malicious input i want to find a neat way to loop through the $_REQUEST array and cleanse it probably by running a mysql function to remove injection code and also a php strip tags routine. How can i do this and repopulate each REQUEST parameter when i wont necessarily know what variables are set eg. sometimes it might be $_REQUEST['username'] sometimes other stuff but different depending on which command i am processing. Any ideas? Thanks.
$_REQUEST is an array, use foreach.
__________________

Village Idiot is offline  
Reply With Quote
Old 11-25-2010, 10:13 PM   #3 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Alternatively you can make use of the excellent array_map function

Code:
$array = array_map('clean', $array);
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 11-26-2010, 12:51 PM   #4 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

array_map is exactly what i'm looking for just looked it up. Thanks.
captainmerton is offline  
Reply With Quote
Old 11-27-2010, 09:33 AM   #5 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Can't get this to work. Here's my code all within a class:

Quote:
function init() {
$this->properties = REQUEST;
$this->properties = array_map('$this->clean()',$this->properties);
}

function clean($variable) {
return strip_tags($variable);
}
captainmerton is offline  
Reply With Quote
Old 11-27-2010, 09:35 AM   #6 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

I always get a php error "The first argument $this->clean should be either NULL or a valid callback. Any thoughts? Got a feeling I'm doing sonthing stupid. Tried everything in the function field I.e. 'clean'.
captainmerton is offline  
Reply With Quote
Old 11-28-2010, 04:59 AM   #7 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

The first argument, the callback, doesn't work that way.

For functions, we can provide a string argument
For static methods we provide an array of the Class and the Static Method
for methods within objects, we provide the object and the method name, so...

array_map(array($obj, 'clean'), $arr);
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 11-28-2010, 01:38 PM   #8 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

I get it now. For $obj i pointed the class to itself with $this and that has made it work. Thanks for your help. Cheers.
captainmerton is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
feedback on my class please frostyboy33 Advanced PHP Programming 7 10-22-2012 09:12 AM
Array mess Killswitch Absolute Beginners 4 12-14-2008 07:35 AM
Altering array data benton General 5 05-18-2008 01:42 PM
Creating a table from loaded data benton General 5 04-20-2008 11:48 AM
Part 1: Getting Started with Array Functions Wildhoney Absolute Beginners 6 10-01-2007 10:53 AM


All times are GMT. The time now is 03:23 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design