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.

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

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线