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 (1) Thread Tools Search this Thread Display Modes
Old 12-23-2007, 10:45 PM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 61
Thanks: 9
Killswitch is on a distinguished road
Default Cleaning data before entering database question

Hello all, I know what to use to clean data before sending it to the database, but have a question about whether this would work out or not...

I am using XAJAX to send all form values in an array to a function which enters the database and returns a success message. Instead of checking if magic quotes is on or off, and cleaning each post individually based upon that, is it safe to run a foreach on the $aFormData array variable and clean just that? Would that clean each of the posted values?

I can clean each by $aFormData = stripslashes($aFormData['section_title']) and so on, but it just creates a huge block and don't think it is much needed.

Basically, this is what the function is looking like so far...

Code:
function addSectionData ( $aFormData ) {

	if(get_magic_quotes_gpc()) {
        	$secname        = stripslashes( $_POST['secname'] );
        	$description    = stripslashes( $_POST['description'] );
		$ordering       = stripslashes( int( $_POST['ordering'] ) );
		$access         = stripslashes( int($_POST['access'] ) );
		$publishing     = stripslashes( int($_POST['publishing'] ) );
        } else {
        	$secname        = $_POST['secname'];
        	$description    = $_POST['description'];
		$ordering       = $_POST['ordering'];
		$access         = $_POST['access'];
		$publishing     = $_POST['publishing'];
        }

	$password = md5( trim ( $aFormData['password'] ) );	
// Query down here, not going to continue, not needed
}
I also plan to slap a mysql_real_escape_string (I made a new function to use instead, just to shorten the name) in the actual query.

One final question... do I have to send the password through strip slashing as well?

Thanks for your support :D
Killswitch is offline  
Reply With Quote
Old 12-24-2007, 01:26 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

In its simplest form you could do the following:

php Code:
$_GET = array_map('strip_tags', $_GET);

Although a foreach loop is also perfectly acceptable. Anything that gets rid of the many lines you currently have is a plus.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following 2 Users Say Thank You to Wildhoney For This Useful Post:
Killswitch (12-24-2007), Matt83 (12-24-2007)
Old 12-24-2007, 01:29 AM   #3 (permalink)
The Wanderer
 
Join Date: Sep 2007
Posts: 12
Thanks: 0
trs21219 is on a distinguished road
Default

it wont matter if the password is cleaned because it is encrypted and it cant harm when its not executable
trs21219 is offline  
Reply With Quote
The Following User Says Thank You to trs21219 For This Useful Post:
Killswitch (12-24-2007)
Old 12-24-2007, 01:48 AM   #4 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 61
Thanks: 9
Killswitch is on a distinguished road
Default

Thanks for your replies. I figured it would be fine, but wasn't quite sure. Didn't think of trying array_map, haven't used it in any of my scripts before.

Edit - Im not sure if I would be able to use $_GET. I read something at the XAJAX site about not being able to access the data with $_GET for some reason or another.

Last edited by Killswitch : 12-24-2007 at 02:13 AM.
Killswitch is offline  
Reply With Quote
Old 12-24-2007, 02:17 AM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

$_POST works exactly the same in array_map, so you can simply drop POST in instead of GET and have it working perfectly! And if you're feeling really clever, you could do both !
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
Killswitch (12-25-2007)
Old 12-24-2007, 08:54 AM   #6 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,053
Thanks: 115
Tanax is on a distinguished road
Default

You could also use FILTER_INPUT_ARRAY

PHP: filter_input_array - Manual
Tanax is offline  
Reply With Quote
The Following User Says Thank You to Tanax For This Useful Post:
sjaq (12-24-2007)
Old 12-24-2007, 03:52 PM   #7 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

I'm gonna go with the array_map function. The FILTER_INPUT_ARRAY takes a little bit too much reading and understanding if you ask me. array_map() in this case, is a lot more safe, easier and faster.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
The Following User Says Thank You to ReSpawN For This Useful Post:
Killswitch (12-25-2007)
Old 12-24-2007, 10:29 PM   #8 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,053
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by ReSpawN View Post
I'm gonna go with the array_map function. The FILTER_INPUT_ARRAY takes a little bit too much reading and understanding if you ask me. array_map() in this case, is a lot more safe, easier and faster.
Ofcourse, it's your choice
Also, you should use mysql_real_escape_string, like you've already mentioned..
Tanax is offline  
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.talkphp.com/general/1797-cleaning-data-before-entering-database-question.html
Posted By For Type Date
TalkPHP - Powered by vBulletin This thread Refback 12-24-2007 01:45 AM

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


All times are GMT. The time now is 04:07 PM.

 
     

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