doujiyan0971 2019-02-17 02:04
浏览 59
已采纳

PHP URL隐藏类别的ID

I am having a doubt that my code "soon to be a website" is weak or easy to hack.

I have read about SQL injection and other security issues, I came to know that the URL should not be something like: "index.php?catid=id" it must be hidden or redirected or routed.

And this is what I am trying to avoid, however, I have tried session_start(); but ended up in a mess.

I might be wrong as well, there might be no danger at all when sending the user from a page to another using anchor click here

Kindly check the code below.

header.php

<div class="header">
<div class="logo">
    <a href="index.php"><img src="images/logo.jpg" alt="logo" /></a>
</div><!--logo ends-->
<div class="navigation">
    <?php

        $cat_sql = "SELECT * FROM category";
        $cat_query = $conn->query($cat_sql);
        while ($cat_results = $cat_query->fetch_array()){
        $category_page = "category.php?categoryID=" .$cat_results['categoryID'];
            //session_start();
            //echo session_id();
            echo "<a href='$category_page'>". $cat_results['name'] ." </a>";
        }
    CloseCon($conn)
    ?>
        <a href="admin.php">Admin</a>
</div><!--navigation ends-->
</div><!-- Header ends here-->

dbconnect.php

$servername = "localhost";
$username = "root";
$password = "123456789";
$database = "accessories";

$conn = new mysqli($servername, $username, $password, $database);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";a

function CloseCon($conn)
{$conn -> close();}
  • 写回答

1条回答 默认 最新

  • dtrj21373 2019-02-17 02:07
    关注

    I'd worry less about IDs being public (that's really not uncommon... it's the norm), and more about how you're querying. Are you making use of MySQLi's support for parameterized queries? They are, single-handedly, the best way to secure your website against SQL Injection vulnerabilities. Anywhere you accept user input, and ship it in a query, ensure it's parameterized.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图