相关疑难解决方法(0)

如何在PHP中阻止SQL注入?

如果插入用户输入而不修改SQL查询,则应用程序容易受到SQL注入的攻击,如下例所示:

$unsafe_variable = $_POST['user_input']; 

mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')");
Run Code Online (Sandbox Code Playgroud)

这是因为用户可以输入类似的内容value'); DROP TABLE table;--,查询变为:

INSERT INTO `table` (`column`) VALUES('value'); DROP TABLE table;--')
Run Code Online (Sandbox Code Playgroud)

可以采取哪些措施来防止这种情况发生?

php mysql sql security sql-injection

2776
推荐指数
28
解决办法
166万
查看次数

防止PHP Web应用程序中的JavaScript注入

在PHP Web应用程序中阻止或阻止JavaScript注入所需的措施是什么,以便不提供敏感信息(PHP,HTML/XHTML和JavaScript中的最佳实践)?

javascript php javascript-injection

10
推荐指数
2
解决办法
2万
查看次数

是使用htmlspecialchars()进行输入/输出HTML清理,对于MySQL数据库糟糕的设计?

可能重复:
什么是最好的PHP输入清理功能?

是使用htmlspecialchars()进行输入/输出HTML清理,对于MySQL数据库糟糕的设计?

你是否应该只是不允许这些"危险"标志,因为它仍会显示b标签,i-tag和其他?怎么这样?

我问,因为它在wiki http://en.wikipedia.org/wiki/HTML_sanitization上

"通过清理用户提交的任何HTML代码,可以使用HTML清理来防止跨站点脚本和SQL注入攻击."

因此,除了使用PDO预处理语句,为了防止SQL注入,我想对所有输入和输出使用这个htmlspecialchars.但也许我应该用别的东西?

这是一个插入语句的好方法吗?:

$type= htmlspecialchars($_POST['animaltype']);
$name= htmlspecialchars($_POST['animalname']);
$age= htmlspecialchars($_POST['animalage']);        
$descr= htmlspecialchars($_POST['animaldescription']);
$foto= htmlspecialchars($_POST['animalfotourl']);
$date=htmlspecialchars($_POST['animalhomelessdate']);



$sqlquery  = "INSERT INTO animals_tbl(animaltype, animalname, animalage, animaldescription, animalfotourl, animalhomelesssince) VALUES (':type',':name',':age',':descr', ':foto', ':date')";


$stmt = $conn->prepare($sqlquery);
$stmt->bindParam(':type',$type, PDO::PARAM_STR);
$stmt->bindParam(':name',$name, PDO::PARAM_STR);
$stmt->bindParam(':age',$age, PDO::PARAM_INT);
$stmt->bindParam(':descr',$descr, PDO::PARAM_STR);
$stmt->bindParam(':foto',$foto, PDO::PARAM_STR);
$stmt->bindParam(':date',$date, PDO::PARAM_STR);

$stmt->execute();
Run Code Online (Sandbox Code Playgroud)

html php database

9
推荐指数
2
解决办法
6819
查看次数

需要自动分页帮助

我有这个脚本:

<?php
if(urldecode($_SERVER['REQUEST_URI']) == "/?articles")
{
    include("Articles.php");
}
?>
Run Code Online (Sandbox Code Playgroud)

这允许我为页面设置自定义 URL。现在,当我需要这样的 URL 时就会出现问题:

/?articles | Page that contains newest articles which loads when user clicks "< Previous" button
/?articles&1 | Page that contains older articles which loads when user clicks "Next >" button
/?articles&2 | Page that contains older than older articles
/?articles&3 | Page that contains old articles
/?articles&4 | Page that contains old articles
/?articles&5 | Page that contains oldest articles
/?articles&6 | Page that contains oldest articles, …
Run Code Online (Sandbox Code Playgroud)

php

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

停止网站上的HTML/Javascript和SQL注入

我拥有一个你有状态框的在线游戏.您可以根据自己的感受更新它.我遇到的问题是用户将java脚本标记放入消息并进入状态.所以当另一个用户来到他们的页面时,会弹出一个弹出框,说哈哈或他们想要的任何东西.

然后我通过使用停止了

$status = mysql_real_escape_string($_POST['status']);
$foo = preg_replace('/[^a-z]/i', null, $status );
Run Code Online (Sandbox Code Playgroud)

这已经停止了任何JavaScript的运行,但现在当有人向某人发送消息时,它会占用空格,因此消息"你好吗"它将显示"howareyou".当然这是安全的,但用户无法读取消息.是否还有其他方法可以阻止脚本标签插入到可用但仍允许空格的情况下?

我也真的害怕有人用XSS攻击我.因为以前,我被告知用户可以在消息中输入内容然后当其他用户打开它时,它会向他们发送密码.....

html php mysql

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