catonthecouchproductions
asked on
Creating a function to help secure forms
I have a form and I want to make it more secure by using strip slashes and I was seeing some examples and is there a way to make that a function to attach it to every field instead of writing it on each one?
Does that make sense? In the function will have strip slashes, then call it on the field?
Is there anything else I should include in the function to help the security?
Does that make sense? In the function will have strip slashes, then call it on the field?
Is there anything else I should include in the function to help the security?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You just need to call the function sanitise_data(); before the code that process a form.
Further than that you could validate each field manually to see if the result is what you are expecting.
For example if you are expecting a number you could check that the result of the $_POST["telephone"] for example is numeric.
if(!is_numeric($_POST["tel ephone"])) {
print "Error telephone can only contain numbers";
}
Further than that you could validate each field manually to see if the result is what you are expecting.
For example if you are expecting a number you could check that the result of the $_POST["telephone"] for example is numeric.
if(!is_numeric($_POST["tel
print "Error telephone can only contain numbers";
}
ASKER
So, i have this at my header.php page
<?php
include_once 'config.php';
include 'santise.php';
sanitise_data();
?>
So this will go for any input? And I am going to go through and make it more valid by like you said numerics, etc.
Can you explain that code? Just for I get a better understanding, i get it slightly.
Thanks for all of this!
<?php
include_once 'config.php';
include 'santise.php';
sanitise_data();
?>
So this will go for any input? And I am going to go through and make it more valid by like you said numerics, etc.
Can you explain that code? Just for I get a better understanding, i get it slightly.
Thanks for all of this!
Now that i look at it again a better way to write it would be as the one below.
Basically it will first check to see it magic_quotes are on. If they are not the it will loop through the $_POST and it will add slashes to every value
Basically it will first check to see it magic_quotes are on. If they are not the it will loop through the $_POST and it will add slashes to every value
function sanitise_data() {
if(!get_magic_quotes_gpc()) {
foreach($_POST as $key=>$value) {
$_POST[$key] = addslashes($_POST[$key]);
}
}
}
ASKER
I just checked and I do have magic quotes on? Does that code work?
the code first checks if magic quotes are on. If they are on then it does nothing.
ASKER
So i do have it on, so still use that code?
You will use it only for portability reasons. I use it because the applications i develop , can be set up into defferent servers with different configurations.
If you are only going to set up your application once then there is no need for it. If you plan on reselling your application to others then you should keep it in.
If you are only going to set up your application once then there is no need for it. If you plan on reselling your application to others then you should keep it in.
ASKER
Alrighty, thank you! So having magic quotes on helps a ton? Security wise?
ASKER
Any other security steps i can take with my form?
If you have magic_quotes on and you validate your input data then you are 99.99% secure from sql injections.
ASKER
Thanks a ton man!
ASKER