diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..12ad6cf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +recaptcha_keys.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..6df0c00 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +Basic Poll Script +# poll diff --git a/index.php b/index.php index 4a15257..0f7bd9a 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,9 @@ $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' => '6LdClsMjAAAAAEaoHxGRckp38hNpZJRU8oR8MNzf', '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.

"; +// 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.

"; } } @@ -65,7 +69,7 @@ foreach ($poll_options as $id => $option) { echo " $option
"; } echo "
"; -echo "
"; +echo "
"; echo ""; echo "
"; echo ""; diff --git a/poll.db b/poll.db index 616cc3b..fd2cdf0 100644 Binary files a/poll.db and b/poll.db differ