$expiry_date) { // Poll has expired echo "This poll has expired."; exit; } // Display the expiry date of the poll echo "This poll ends at: " . date('l, F j, Y', $expiry_date); // Display the poll question echo "

$question

"; // Check if the form has been submitted if (isset($_POST['submit'])) { // Form has been submitted // Verify the reCaptcha response $url = 'https://www.google.com/recaptcha/api/siteverify'; $data = array('secret' => $recaptcha_secret, 'response' => $_POST['g-recaptcha-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); $response = file_get_contents($url, false, $context); $result = json_decode($response); if ($result->success) { // reCaptcha was successful // Save the vote to the database $stmt = $db->prepare("INSERT INTO poll_votes (option_id) VALUES (?)"); $stmt->execute([$_POST['option']]); // Redirect the user to a different page header('Location: results.php'); exit; } else { // reCaptcha was unsuccessful // Display an error message echo "

There was an error with the reCaptcha. Please try again.

"; } } // Display the poll form echo "
"; foreach ($poll_options as $id => $option) { echo " $option
"; } echo "
"; echo "
"; echo ""; echo "
"; echo ""; echo "
"; // Display the "View Results" link echo "View Results"; ?>