connect_error) { die("Connection failed: " . $conn->connect_error); } $error_message = ''; $success_message = ''; $hcaptcha_secret = 'ES_91395394d002433e97cc511fde9889aa'; if (isset($_POST['register'])) { $name = $_POST['name']; $email = $_POST['email']; $password = password_hash($_POST['password'], PASSWORD_ARGON2ID); $hcaptcha_response = $_POST['h-captcha-response']; // Verificar hCaptcha $verify_url = 'https://hcaptcha.com/siteverify'; $data = array( 'secret' => $hcaptcha_secret, 'response' => $hcaptcha_response ); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data), ), ); $context = stream_context_create($options); $result = file_get_contents($verify_url, false, $context); $verification = json_decode($result); if ($verification && $verification->success) { $stmt_check = $conn->prepare("SELECT COUNT(*) AS count FROM `tbl_user` WHERE `email` = ?"); $stmt_check->bind_param("s", $email); $stmt_check->execute(); $result_check = $stmt_check->get_result(); $row = $result_check->fetch_assoc(); if ($row['count'] > 0) { $error_message = 'The email is already in use.'; } else { $stmt_insert = $conn->prepare("INSERT INTO `tbl_user`(`name`, `email`, `password`) VALUES (?, ?, ?)"); $stmt_insert->bind_param("sss", $name, $email, $password); if ($stmt_insert->execute()) { $success_message = 'User registered successfully.'; } else { $error_message = 'Error: ' . $stmt_insert->error; } $stmt_insert->close(); } $stmt_check->close(); } else { $error_message = 'Captcha verification failed.'; } } if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['google_email'])) { $google_email = $_POST['google_email']; $google_name = $_POST['google_name']; $stmt_check = $conn->prepare("SELECT COUNT(*) AS count FROM `tbl_user` WHERE `email` = ?"); $stmt_check->bind_param("s", $google_email); $stmt_check->execute(); $result_check = $stmt_check->get_result(); $row = $result_check->fetch_assoc(); if ($row['count'] == 0) { $stmt_insert = $conn->prepare("INSERT INTO `tbl_user`(`name`, `email`) VALUES (?, ?)"); $stmt_insert->bind_param("ss", $google_name, $google_email); $stmt_insert->execute(); $stmt_insert->close(); } $_SESSION['user'] = $google_name; $_SESSION['email'] = $google_email; echo json_encode(['success' => true]); exit(); } $conn->close(); ?> Register