website/public/API/newComment.php

40 lines
972 B
PHP
Raw Normal View History

2020-10-27 13:46:22 +01:00
<?php
require './vendor/autoload.php';
2021-04-12 20:36:45 +02:00
include("./lib/config.php");
include("./lib/mysql.php");
2020-10-27 13:46:22 +01:00
use GuzzleHttp\Client;
2020-12-30 23:02:45 +01:00
$data = array(
'secret' => $secretkey,
'response' => $_POST['h-captcha-response']
);
2020-10-27 13:46:22 +01:00
$client = new Client();
$response = $client->post("https://hcaptcha.com/siteverify", [
"form_params" => $data
]);
$responseData = json_decode($response->getBody());
2020-10-27 13:46:22 +01:00
2020-12-30 23:02:45 +01:00
if($responseData->success) {
$article =$conn->escape_string($_POST["pagename"]);
2020-12-30 23:02:45 +01:00
$name = $conn->escape_string($_POST["name"]);
$email = $conn->escape_string($_POST["email"]);
$comment = $conn->escape_string($_POST["comment"]);
$sql = "INSERT INTO comments (name, email, comment, article) VALUES ('$name', '$email', '$comment', '$article')";
if ($conn->query($sql) === TRUE) {
2021-11-09 12:28:04 +01:00
header("Location: " . $_SERVER["HTTP_REFERER"]);
2020-12-30 23:02:45 +01:00
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
2020-10-27 13:46:22 +01:00
} else {
2020-12-30 23:02:45 +01:00
echo "Failed to verify captcha.";
}