From 60e6d851f6f23984f1408441d205a6842ce4ffa3 Mon Sep 17 00:00:00 2001 From: deepend Date: Mon, 2 Jan 2023 01:45:57 +0000 Subject: [PATCH] first commit --- .gitignore | 1 + README.md | 2 ++ index.php | 56 ++++++++++++++++++++++++++++------------------------- poll.db | Bin 8192 -> 8192 bytes 4 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 .gitignore create mode 100644 README.md 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 616cc3b8d6166915c6bcc7b8cfc3d6391ec4d3cd..fd2cdf0e5c1e7ee2965a6e6e4510fa1d3ba44e67 100644 GIT binary patch delta 41 ucmZp0XmFSy&1gGO#+lJ}W5N=C4krHZ4E%rizi$>4c+Jnr%*4b9LYx2t-wJF1 delta 37 tcmZp0XmFSy&1f@G#+lJ(W5N=CHb(wG4E%pK3kp2rpBTWy!o{p&3O@h<