Back to Basics: Scrubbing POSTs in PHP

Sunday, April 20, 2008, 1:39 AM
Code by John

Post values are writable, in addition to being readable. I've noticed a lot of code that seems to forget that you can scrub and then dump data into the POST values. Consider the following:

foreach ($_POST as $key=>$value){
$_POST[$key]=htmlentities($_POST[$key]);
}

This code takes every POSTed variable and converts it using the PHP command 'htmlentities'.

More sexy code, huh? It's actually very handy, because this allows you, especially if you combine it with a few functions, to rapidly scrub all user input. I actually embed this type of code to scrub GETs and POSTs in my MySQL connection scripts that I use as includes at the beginning of all my PHP. That way, user POSTed variables are scrubbed automatically before even being pulled into a variable that might end up in the database.

Advertisements




Mail article to a friend

© 2008 Pro Content and Design. All rights reserved.


Tools

Check Google PageRank


Recent articles

  1. Fixing an open relay on Postfix
  2. Google updates PageRanks
  3. The joy of errors: 426 Failure writing network stream
  4. Back to Basics: Scrubbing POSTs in PHP
  5. Back to basics: Scrubbing for alphanumeric input in PHP
  6. Back to basics: Using PHP's GD library to make a border
  7. Blacklisting by country works
  8. GoDaddy: something nice to say
  9. TV's fetish for making the internet sound evil
  10. Small user-generated websites

Welcome!

Wonder where to start with your web design business?

This blog follows along with my efforts to build and grow a website design business, Pro Content and Design.

The goal of this blog is to fill in blanks that may be empty as you get your business rolling.

This blog, particularly the source code section, is not intended for beginners. If you are not comfortable with databases, Ajax, DOM objects and other advanced methods, I strongly suggest you go take a look over at W3 Schools before even reading -- let alone tinkering with -- any of the code here.

I hope this blog has some value to web designers as they attempt to get their businesses going.

Good luck, and happy reading.

Thank you,
John Crawford
Pro Content and Design

Books


I highly recommend Art of the Start if you have no idea where to start with marketing.

Links

Coding
W3 Schools
IBM's Mastering Ajax Series

Graphic Design
Worth 1000
Stock.XCHNG
Urban Fonts

Website Software
Apache Web Server
SquirrelMail
PHP/Zend

Website Design Issues
Non-Standard Character Guide
Google Trends
Search Engine Optimization Analyzer

Business
Guy Kawasaki's Blog
Seth Godin's Blog
Freakonomics

Computers
NewEgg

My Main Website
Pro Content and Design

Websites I have built
PunxsyPage: local free classifieds website

Farm N Land: low-cost real estate listing website

InvestYoung: semi-defunct finance blog

Groundhog Festival: for the local summer festival

Weather Discovery Center

My Webapps
TV Stations Transmitter Database

Google PageRank Checker

Website where I did the code, database and admin
Tour de Toona: annual bicycle race in Altoona, PA