note 82120 added to function.addslashes
| From: | (adityabhai@gmail.com) | Date: | Fri, 28 Mar 2008 05:59:56 +0000 |
| Subject: | note 82120 added to function.addslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137656@lists.php.net to get a copy of this message | ||
Automagically add slashes to $_POST variables. It helps to prevent some sql injection attacks. Also
works with $_GET variables.
FILE NAME: 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.
?>
----
Server IP: 59.162.86.33
Probable Submitter: 122.169.40.153
----
Manual Page -- http://www.php.net/manual/en/function.addslashes.php
Edit -- https://master.php.net/note/edit/82120
Del: integrated -- https://master.php.net/note/delete/82120/integrated
Del: useless -- https://master.php.net/note/delete/82120/useless
Del: bad code -- https://master.php.net/note/delete/82120/bad+code
Del: spam -- https://master.php.net/note/delete/82120/spam
Del: non-english -- https://master.php.net/note/delete/82120/non-english
Del: in docs -- https://master.php.net/note/delete/82120/in+docs
Del: other reasons-- https://master.php.net/note/delete/82120
Reject -- https://master.php.net/note/reject/82120
Search -- https://master.php.net/manage/user-notes.php