deletecomment.php 992 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. session_start();
  3. $http_host = $_SERVER["HTTP_HOST"];
  4. $doc_root = $_SERVER["DOCUMENT_ROOT"] . "/";
  5. include $doc_root . "functions.php";
  6. $proto = get_protocol();
  7. $con = start_db();
  8. $server = $proto . $http_host;
  9. $pserver = substr($server, 0, strpos($http_host, ':')); // public server
  10. if (!check_session($con)){
  11. http_response_code(401); // Not logged in: Forbidden.
  12. }
  13. else{
  14. $id = intval(mysqli_real_escape_string($con, $_GET["i"]));
  15. if (strlen($id) < 1){
  16. http_response_code(400); // No or bad ID: Bad request.
  17. }
  18. else{
  19. if (mysqli_num_rows(mysqli_query($con, "SELECT id FROM project_comment WHERE id = $id;")) == 0){
  20. http_response_code(404); // Unexistent id: Not found.
  21. }
  22. else{
  23. mysqli_query($con, "DELETE FROM project_comment WHERE id = $id;");
  24. http_response_code(200); //OK.
  25. }
  26. }
  27. }
  28. ?>