| | 21 | |
|---|
| | 22 | // Step 2: Check if CAPTCHA-Token exists |
|---|
| | 23 | if (empty($_POST['slidercaptcha_token'])) { |
|---|
| | 24 | // SliderCaptcha not solved → Show SliderCaptcha |
|---|
| | 25 | $showCaptcha = true; |
|---|
| | 26 | } else { |
|---|
| | 27 | // Step 3: CAPTCHA-Token exists → Validate Token |
|---|
| | 28 | $captchaToken = (string)($_POST['slidercaptcha_token'] ?? ''); |
|---|
| | 29 | |
|---|
| | 30 | if ($captchaToken === 'CAPTCHA_UNAVAILABLE') { |
|---|
| | 31 | // Special Token: 'CAPTCHA_UNAVAILABLE' |
|---|
| | 32 | // Check if service is really down! |
|---|
| | 33 | $ch = curl_init('https://slidercaptcha.net/api/v1/verify.php'); |
|---|
| | 34 | curl_setopt_array($ch, [ |
|---|
| | 35 | CURLOPT_POST => true, |
|---|
| | 36 | CURLOPT_RETURNTRANSFER => true, |
|---|
| | 37 | CURLOPT_HTTPHEADER => ['Content-Type: application/json'], |
|---|
| | 38 | CURLOPT_POSTFIELDS => json_encode(['token' => 'test', 'secret_key' => 'test']), |
|---|
| | 39 | CURLOPT_TIMEOUT => 3, |
|---|
| | 40 | CURLOPT_CONNECTTIMEOUT => 3 |
|---|
| | 41 | ]); |
|---|
| | 42 | |
|---|
| | 43 | $testResponse = curl_exec($ch); |
|---|
| | 44 | $testHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|---|
| | 45 | curl_close($ch); |
|---|
| | 46 | |
|---|
| | 47 | // If service is NOT available (Timeout, Connection Error, etc.) |
|---|
| | 48 | if ($testResponse === false || $testHttpCode === 0) { |
|---|
| | 49 | // Service is down → Allow Bypass |
|---|
| | 50 | error_log('SliderCaptcha service unavailable - allowing bypass for email: ' . $email); |
|---|
| | 51 | $captchaVerified = true; |
|---|
| | 52 | $captchaServiceAvailable = false; |
|---|
| | 53 | } else { |
|---|
| | 54 | // Service is NOT down → Bot-Attack! |
|---|
| | 55 | error_log('SECURITY WARNING: Attempted CAPTCHA bypass with available service for email: ' . $email); |
|---|
| | 56 | $errors['captcha'] = 'Invalid CAPTCHA token. Please try again.'; |
|---|
| | 57 | $captchaVerified = false; |
|---|
| | 58 | } |
|---|
| | 59 | |
|---|
| | 60 | } else { |
|---|
| | 61 | // Normal Token → Verify that token |
|---|
| | 62 | $verifyPayload = json_encode([ |
|---|
| | 63 | 'token' => $captchaToken, |
|---|
| | 64 | 'secret_key' => 'sk_live_26918...provided by DSLM IT-CONSULTING' |
|---|
| | 65 | ]); |
|---|
| | 66 | $ch = curl_init('https://slidercaptcha.net/api/v1/verify.php'); |
|---|
| | 67 | curl_setopt_array($ch, [ |
|---|
| | 68 | CURLOPT_POST => true, |
|---|
| | 69 | CURLOPT_RETURNTRANSFER => true, |
|---|
| | 70 | CURLOPT_HTTPHEADER => [ |
|---|
| | 71 | 'Content-Type: application/json' |
|---|
| | 72 | ], |
|---|
| | 73 | CURLOPT_POSTFIELDS => $verifyPayload, |
|---|
| | 74 | CURLOPT_TIMEOUT => 5, |
|---|
| | 75 | CURLOPT_CONNECTTIMEOUT => 5 |
|---|
| | 76 | ]); |
|---|
| | 77 | |
|---|
| | 78 | $verifyResponse = curl_exec($ch); |
|---|
| | 79 | $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|---|
| | 80 | $curlError = curl_error($ch); |
|---|
| | 81 | curl_close($ch); |
|---|
| | 82 | |
|---|
| | 83 | // Network-/Servererror |
|---|
| | 84 | if ($verifyResponse === false || $httpCode === 0) { |
|---|
| | 85 | // Service ist down → Allow Bypass |
|---|
| | 86 | error_log('SliderCaptcha service unavailable during verification - allowing bypass for email: ' . $email); |
|---|
| | 87 | $captchaVerified = true; |
|---|
| | 88 | $captchaServiceAvailable = false; |
|---|
| | 89 | } elseif ($httpCode !== 200) { |
|---|
| | 90 | $errors['captcha'] = 'SliderCaptcha verification failed. Please try again.'; |
|---|
| | 91 | $captchaVerified = false; |
|---|
| | 92 | } else { |
|---|
| | 93 | $data = json_decode($verifyResponse, true); |
|---|
| | 94 | // Invalid Response |
|---|
| | 95 | if (!is_array($data) || empty($data['success'])) { |
|---|
| | 96 | $errors['captcha'] = 'SliderCaptcha verification failed. Please try again.'; |
|---|
| | 97 | $captchaVerified = false; |
|---|
| | 98 | } else { |
|---|
| | 99 | // Optional: Check Score |
|---|
| | 100 | if (isset($data['score']) && $data['score'] < 0.5) { |
|---|
| | 101 | $errors['captcha'] = 'SliderCaptcha verification failed. Please try again.'; |
|---|
| | 102 | $captchaVerified = false; |
|---|
| | 103 | } else { |
|---|
| | 104 | $captchaVerified = true; |
|---|
| | 105 | } |
|---|
| | 106 | } |
|---|
| | 107 | } |
|---|
| | 108 | } |
|---|
| | 109 | |
|---|
| | 110 | |
|---|
| | 111 | if ($captchaVerified) { |
|---|
| | 112 | // ✓ SliderCaptcha successfully solved → Check if Email already exists in subscripton table |
|---|
| 17 | /* | 113 | /* |
|---|
| 18 | *** put your code here to check Email against database *** | 114 | *** put your code here to check Email against database *** |
|---|
| 19 | */ | 115 | */ |
|---|
| 20 | | 116 | |
|---|
| 21 | // Simple check to demonstrate what happens if email already exists in database: | 117 | // Simple check to demonstrate what happens if email already exists in database: |
|---|
| 22 | if ($email == "joe.doe@example.com") { | 118 | if ($email == "joe.doe@example.com") { |
|---|
| 23 | $errors['email'] = "This email-address already exists in our database"; | 119 | $errors['email'] = "This email-address already exists in our database"; |
|---|
| 24 | } else { | 120 | } else { |
|---|
| 25 | /* | 121 | /* |
|---|
| 26 | *** put your code here to store the email-address in your database *** | 122 | *** put your code here to store the email-address in your database *** |
|---|
| 27 | */ | 123 | */ |
|---|
| 28 | $successMessage = 'Thank you for your subscription!'; | 124 | $successMessage = 'Thank you for your subscription!'; |
|---|
| | 186 | |
|---|
| | 187 | <?php if ($showCaptcha): ?> |
|---|
| | 188 | <script> |
|---|
| | 189 | // SliderCaptcha needs to be solved bevore form will be finally submitted |
|---|
| | 190 | document.addEventListener('DOMContentLoaded', function() { |
|---|
| | 191 | |
|---|
| | 192 | let captchaFailed = false; |
|---|
| | 193 | // Check if SliderCaptcha is available |
|---|
| | 194 | if (typeof SliderCaptcha === 'undefined') { |
|---|
| | 195 | console.warn('SliderCaptcha script not loaded, waiting for timeout...'); |
|---|
| | 196 | captchaFailed = true; |
|---|
| | 197 | document.getElementById('slidercaptcha_token').value = 'CAPTCHA_UNAVAILABLE'; // set marker |
|---|
| | 198 | document.getElementById('subscriptionForm').submit(); // backend is checking if service is really unavailable |
|---|
| | 199 | } else { |
|---|
| | 200 | // Display SliderCaptcha |
|---|
| | 201 | SliderCaptcha.execute() |
|---|
| | 202 | .then(function(response) { |
|---|
| | 203 | if (!captchaFailed) { |
|---|
| | 204 | document.getElementById('slidercaptcha_token').value = response.token; |
|---|
| | 205 | document.getElementById('subscriptionForm').submit(); |
|---|
| | 206 | } |
|---|
| | 207 | }) |
|---|
| | 208 | .catch(function(error) { |
|---|
| | 209 | // SliderCaptcha was cancelled by the user |
|---|
| | 210 | console.error('SliderCaptcha error:', error); |
|---|
| | 211 | }); |
|---|
| | 212 | } |
|---|
| | 213 | }); |
|---|
| | 214 | </script> |
|---|
| | 215 | <?php endif; ?> |
|---|
| | 216 | |
|---|
| | 217 | <!-- SliderCaptcha Embed Script --> |
|---|
| | 218 | <script src="https://slidercaptcha.net/embed.js" |
|---|
| | 219 | data-sitekey="pk_live_b4a35...provided by DSLM IT-CONSULTING" |
|---|
| | 220 | data-mode="live" |
|---|
| | 221 | data-language="en"> |
|---|
| | 222 | </script> |
|---|