WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : addslashes automatically to $_POST variables
Categories : PHP, Form Processing, Security Click here to Update Your Picture
Aaron Mitcham
Date : Oct 28th 2006
Grade : 1 of 5 (graded 1 times)
Viewed : 3635
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Aaron Mitcham
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

Automagically add slashes to $_POST variables.
It helps to prevent some sql injection attacks.
Also works with $_GET variables.



input_cl.php
<?php
//create array to temporarily grab variables
$input_arr = array();
//grabs the $_POST variables and adds slashes
foreach ($_POST as $key => $input_arr) {
$_POST[$key] = addslashes($input_arr);
}
?>



Just put this at the top of your script that gets the variables. Here is an example.

Usage Example
<?php
include("input_cl.php");
// all $_POST variables have slashes added to them
$f_name = $_POST["f_name"];
$l_name = $_POST["l_name"];
$phone_num = $_POST["phone_num"];
$address1 = $_POST["address1"];
$address2 = $_POST["address2"];
$city = $_POST["city"];
$State = $_POST["State"];
$zip = $_POST["zip"];

//sql insert code goes here.



A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session.
Categories : PHP, GD image library, Form Processing, Security
send_mail function to defeat Header Injection Hacking/Spamming
Categories : PHP, Email, Form Processing, Security
A PHP function to encrypt and decrypt a number or string or a combination of the two.
Categories : PHP, Encryption, Security
Dollar Serial Number Validator
Categories : PHP, Security, Algorithms
Using this script anyone can easily get a form result to his/her mailbox. You can use this script for any form 2 mail purpose.
Categories : PHP, Mail, Form Processing
MD5 secured login
Categories : PHP, Java Script, Authentication, Security
Secure URL $_GET
Categories : PHP, Data Validation, Security
Encoding data using PGP via PHP's proc_* functions
Categories : Cryptography, Security, Email, PHP, PGP
A very simple PHP single password cookie based login without usernames.
Categories : PHP, Cookies, Security, Beginner Guides
Easily Grant Temporary SSH Access to yourself when in remote location
Categories : PHP, Linux, Cron, Security
Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides
Simple PHP Form Field Generator
Categories : PHP, Beginner Guides, Form Processing, HTML and PHP
SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge response login algorithms over an insecure connection.
Categories : Algorithms, PHP, Security
A simple PHP login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page.
Categories : PHP, Sessions, Security, Authentication
 Dave Silvia wrote : 1664
I don`t quite understand.  Aren`t slashes added by the request mechanism for posting from forms?  My experience has been having to remove them, not add them.

I must be missing a point here somewhere...
 
 Aaron Mitcham wrote :1665
Wouldn`t stripslashes($input_arr)work just as well?
Besides in every piece of code I`ve written I had to add slashes so that punctuation doesn`t break the script.

Aaron