我怎样才能提高此 php 代码的安全性?

How could I improve the security of this php code?

我已经创建了 PHP 代码:

<?php

  include("../config.php");

  if(!isset($_COOKIE["sessionid"])) {
      header("location:../error_pages/403.php");
  } else {
      $value = $_COOKIE["sessionid"];
      $query = "SELECT * FROM users WHERE sessionid = ?";

      $stmt = $conn->prepare($query);
      $stmt->bind_param("s",$value);
      $stmt->execute();
      $result = $stmt->get_result();

      $rowcount = $result->num_rows;
      if ($rowcount != 1 ) {
          header("location:../error_pages/403.php");
      } else {
          $file = "/path/to/file/";
          header('Content-Description: File Transfer');
          header('Content-Disposition: attachment; filename='.basename("File_Name"));
          ob_clean();
          flush();
          readfile($file);
      }
  };
?>

我想知道是否有一种方法可以操纵 sessionid cookie 以允许 SQL 注入。以及此下载是否安全。该文件未存储在可公开访问的文件夹中。

为了防止会话被窃取,我只通过 TLS 提供登录页面,还有其他方法可以窃取会话吗?

通过使用查询参数,您可以避免 SQL 注入。

您的代码可能容易受到会话劫持。以下是一些提示和资源: