dongnong3019 2016-12-14 21:45
浏览 65

PHP / MySQL加密URl中的ID

i'm a newbie and I just built a CRUD system but its not secure at all. The edit page has the ID number in the URL and users can simple just randomly type ID's to access other records in the database.

http://example.com/example_edit.php?id=2

<?php

include_once("connection.php");


$result = mysqli_query($mysqli, "SELECT * FROM mkregistrationchecklists WHERE login_id=".$_SESSION['id']." ORDER BY id DESC");
?>

<tbody>
<?php
while($res = mysqli_fetch_array($result)) {        

    echo "<tr>";
    echo "<td>".$res['id']."</td>";
    echo "<td><span class='label ".$res['labelwarning']."'>".$res['status']."</span></td>";
    echo "<td>".$res['todaysdatetime']."</td>";
    echo "<td>".$res['tag']."</td>";
    echo "<td>".$res['serialnumber']."</td>";   
    echo "<td>".$res['currentequipment']."</td>"; 
    echo "<td>".$res['company']."</td>";  

     if ($res['status'] == "Submitted") {
    echo "<td><a href='page_read.php?id=$res[id]' class='btn btn-default glyphicon glyphicon-eye-open'></a></td>";
} else{
    echo "<td><a href=\"page_edit.php?id=$res[id]\" class='btn btn-default fa fa-pencil-square'></a> | <a href=\"page_delete.php?id=$res[id]\" class='btn btn-danger fa fa-trash' onClick=\"return confirm('Are you sure you want to delete?')\"></a></td>"; 
}

    echo "</tr>";



}
?>
</tbody>

What is the best approach in securing this?

Should i encrypt like this?

$secure_id = $_GET['id'];
$decryped_id = base64_decode($secure_id);

I updated my code, im saving the records according to the login_id but it still looks unprofessional with the id tag in the urls.

  • 写回答

1条回答 默认 最新

  • dqdmvg7332 2016-12-14 21:55
    关注

    You have to add user / record owner unique identification into all SQL queries, typically :

    $query = "SELECT * FROM table WHERE id = 1 AND user_id = 2";
    

    with this approach you can be sure that user access only his records. Id of logged in user can be placed somewhere in SESSION.

    Hiding or hashing ids is not recommended, it's a anti-pattern and security through obscurity.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么