我的PHP项目中有这个url,帮助用户在特定日期查看他的收入和结果,我使用的代码是PDO,在这张图片中,我有id = 18的数据,但是当我改变它以查看注射是否可能,从18到另一个id值,它工作并给我这个ID的数据。我只在会话中发送用户名。
我有这个PHP PDO代码:
<?php
require_once('../include/inner_global.php');
$id=$_REQUEST['id'];
$hostdb="localhost";
$namedb="architect";
$userdb="root";
$passdb="root";
$d = "";
$result1 = 0;
$result2 = 0;
$result3 = 0;
$result4 = 0;
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec("SET CHARACTER SET utf8");
if(isset($_POST['submitDate'])){
if(!isset($_POST['Date'])){
echo "No date selected";
}else{
echo $d = date('Y-m-d',strtotime($_POST['Date']));
}
//Workers Table:
$sql1= "SELECT SUM(total_pay) AS total_w FROM workers WHERE date_of_pay = :d1 AND projects_id = :id";
$stmt1 = $conn->prepare($sql1);
$stmt1->bindValue(":d1", $d);
$stmt1->bindValue(":id", $id);
$count1 = $stmt1->execute();
$result1 = $stmt1->fetch(PDO::FETCH_ASSOC);
...
此查询显示在html表格中:
<tr>
<?php if($result1['total_w'] === null):?>
<td align="center">لا يوجد تكاليف عمال في هذا التاريخ</td>
<?php else: ?>
<td align="center">
<?php
{
echo $result1['total_w'];
}
?>
<?php endif; ?>
</td>
我想修复的是,当我们在项目id = N时,我不会让用户访问项目id = M的数据,除非他退出,然后再次登录,然后选择id = m的项目,看看它