Sanitize user inputs using php
Posted by bput4all on October 7, 2012 · 11 Comments
function cleaninput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
return $output;
}
function sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
$input = cleaninput($input);
$output = mysql_real_escape_string($input);
}
return $output;
}
// Usage:
$bad_string = "Hi! <script src='http://www.evilsite.com/bad_script.js'></script> It's a good day!";
$good_string = sanitize($bad_string);
// $good_string returns "Hi! It\'s a good day!"
// Also use for getting POST/GET variables
$_POST = sanitize($_POST);
$_GET = sanitize($_GET);
As I web site possessor I believe the content material here is rattling great , appreciate it for your efforts. You should keep it up forever! Best of luck.
An interesting discussion is worth comment. I think that you should write more on this topic, it might not be a taboo subject but generally people are not enough to speak on such topics. To the next. Cheers
excellent post. i want to thank you for this informative read, i really appreciate sharing this great post. keep up your work. lista de emails lista de emails lista de emails lista de emails lista de emails
I’m still learning from you, as I’m trying to achieve my goals. I definitely enjoy reading all that is posted on your site.Keep the tips coming. I loved it!
I simply want to say I am just all new to blogging and site-building and truly savored this web site. Almost certainly I’m planning to bookmark your blog post . You really come with incredible well written articles. Regards for sharing with us your website.
Wow! This could be one particular of the most helpful blogs We have ever arrive across on this subject. Basically Great. I am also a specialist in this topic therefore I can understand your effort.
chanel wallet http://chanelwallet.ezweb123.com/
Good site you’ve got here.. It’s hard to find good quality writing like yours these days. I honestly appreciate individuals like you! Take care!!
I just want to tell you that I am beginner to blogs and absolutely savored your blog. Very likely I’m likely to bookmark your site . You definitely come with remarkable articles. Thank you for sharing with us your blog.
Very interesting topic, regards for putting up.
Very interesting subject, regards for putting up.
Very interesting subject, appreciate it for putting up.