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 06-27-2008, 08:34 PM   #1 (permalink)
The Acquainted
 
drewbee's Avatar
 
Join Date: May 2008
Posts: 175
Thanks: 9
drewbee is on a distinguished road
Default automatically clean form posted variables.

I use this as a simple cleanup of posted variables (I only do post automatically), as well as a nice trim to the data. This is nice because even if an array is given, it will follow it...

This is a basic piece of my Form class. This form class is simply the superclass to all of my sub-classes. There is more stuff I use within this as well, but you get the idea with this I think.

only strip_slashes() if you have the lovely magic quotes on.

This does pass by ref as well, so you can throw anything you want into it and it modifies the original variable without returning anything.

PHP Code:
<?php
class Form extends Page
{
 
    var 
$isPostBack;
 
    function 
Form()
    {
          
$this->isPostBack count($_POST) > true false;
          if (
$this->isPostBack)
          {
              
array_walk_recursive($_POST, array($this,'cleanGlobal'));
          }
    }
 
    function 
cleanGlobal(&$var$key null)
    {
        if(
is_array($var))
        { 
            
array_walk_recursive($var, array($this'cleanGlobal'));
        } 
        else 
        {
            
// How do you want each variable handled?
            
$var trim(stripslashes(($var)); 
        }
    }
 
}
?>
__________________
There are No Stupid Questions. But there a LOT of Inquisitive Idiots.

Last edited by drewbee : 07-07-2008 at 03:29 PM. Reason: wow formating ftw...
Send a message via AIM to drewbee
drewbee is offline  
Reply With Quote
Old 06-28-2008, 03:24 PM   #2 (permalink)
The Acquainted
 
drewbee's Avatar
 
Join Date: May 2008
Posts: 175
Thanks: 9
drewbee is on a distinguished road
Default

Procedural:

PHP Code:
function cleanGlobal(&$var$key null)
{
    if(
is_array($var))
    { 
        
array_walk_recursive($var'cleanGlobal');
    } 
    else 
    {
        
// How do you want each variable handled?
        
$var trim(stripslashes(($var)); 
    }
}
 
if (
count($_POST) > 0)
{
    
array_walk_recursive($_POST'cleanGlobal');

__________________
There are No Stupid Questions. But there a LOT of Inquisitive Idiots.

Last edited by drewbee : 07-07-2008 at 03:27 PM.
Send a message via AIM to drewbee
drewbee 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


All times are GMT. The time now is 09:54 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