相关疑难解决方法(0)

用PHP清理用户输入的最佳方法是什么?

是否有一个catchall函数适用于清理SQL注入和XSS攻击的用户输入,同时仍允许某些类型的html标记?

php security xss user-input sql-injection

1069
推荐指数
14
解决办法
50万
查看次数

最终的清洁/安全功能

我有很多用户输入$_GET$_POST...目前我总是写mysql_real_escape_string($_GET['var'])..

我想知道你是否可以创建一个能够立即保护,转义和清理$_GET/ $_POST数组的函数,因此每次使用用户输入时都不必处理它.

我在想一个功能,例如cleanMe($input),和它里面,它应该做的mysql_real_escape_string,htmlspecialchars,strip_tags,stripslashes(我想这是所有做它的清洁与安全),然后返回$input.

这可能吗?使得对所有工作的功能$_GET$_POST,所以你会做只有这个:

$_GET  = cleanMe($_GET);
$_POST = cleanMe($_POST);
Run Code Online (Sandbox Code Playgroud)

那么在以后的代码中,当您使用eg $_GET['blabla']或者$_POST['haha']它们时,它们是安全的,剥离的等等?

试了一下自己:

function cleanMe($input) {
   $input = mysql_real_escape_string($input);
   $input = htmlspecialchars($input, ENT_IGNORE, 'utf-8');
   $input = strip_tags($input);
   $input = stripslashes($input);
   return $input;
}
Run Code Online (Sandbox Code Playgroud)

php security xss sql-injection

57
推荐指数
3
解决办法
6万
查看次数

PHP清理数据

我是编码和PHP的新手,因此我想了解清理表单数据的最佳方法是什么,以避免格式错误的页面,代码注入等.我在下面找到的示例脚本是一个很好的例子吗?

代码最初发布于http://codeassembly.com/How-to-sanitize-your-php-input/

/**
 * Sanitize only one variable .
 * Returns the variable sanitized according to the desired type or true/false 
 * for certain data types if the variable does not correspond to the given data type.
 * 
 * NOTE: True/False is returned only for telephone, pin, id_card data types
 *
 * @param mixed The variable itself
 * @param string A string containing the desired variable type
 * @return The sanitized variable or true/false
 */

function sanitizeOne($var, $type)
{ …
Run Code Online (Sandbox Code Playgroud)

php sanitize

13
推荐指数
3
解决办法
4万
查看次数

用于登录表单的简单sql注入解决方案?

我看到了几个例子,人们用这种方式在登录表单中查询数据库.我不完全确定这是安全登录表单的最佳方式.

这是PHP中的查询:

    $query = "SELECT * FROM users WHERE usern = '".$_POST['username']."' AND passw = '".md5($_POST['password'])."'";
Run Code Online (Sandbox Code Playgroud)

是否在密码帖子上有md5()以避免sql注入?我认为md5函数会将所有字符和sql字符串转换为32个char字符串.

我可以通过哪些其他方式保护登录表单?

php sql login code-injection

1
推荐指数
1
解决办法
3387
查看次数

标签 统计

php ×4

security ×2

sql-injection ×2

xss ×2

code-injection ×1

login ×1

sanitize ×1

sql ×1

user-input ×1