fork download
  1. <?php
  2. $siteKey = 'YOUR_SITE_KEY';
  3. $secretKey = 'YOUR_SECRET_KEY';
  4.  
  5. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  6. $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS);
  7. $line_id = filter_input(INPUT_POST, 'line_id', FILTER_SANITIZE_SPECIAL_CHARS);
  8. $recaptchaResponse = $_POST['g-recaptcha-response'];
  9.  
  10. // reCAPTCHAの検証
  11. $url = 'https://www.google.com/recaptcha/api/siteverify';
  12. $data = [
  13. 'secret' => $secretKey,
  14. 'response' => $recaptchaResponse,
  15. 'remoteip' => $_SERVER['REMOTE_ADDR']
  16. ];
  17.  
  18. $options = [
  19. 'http' => [
  20. 'method' => 'POST',
  21. 'header' => 'Content-type: application/x-www-form-urlencoded',
  22. 'content' => http_build_query($data)
  23. ]
  24. ];
  25.  
  26. $context = stream_context_create($options);
  27. $response = file_get_contents($url, false, $context);
  28. $responseData = json_decode($response);
  29.  
  30. if ($responseData->success && $responseData->score > 0.5) {
  31. // reCAPTCHAの検証成功
  32. $postData = $name . ',' . $line_id . "\n";
  33. file_put_contents('data.txt', $postData, FILE_APPEND);
  34. header('Location: index.php'); // 投稿後にindex.phpへリダイレクト
  35. } else {
  36. // reCAPTCHAの検証失敗
  37. echo "reCAPTCHAの検証に失敗しました。";
  38. // エラー処理を記述
  39. }
  40. } else {
  41. // POSTリクエスト以外の場合
  42. header('Location: index.php');
  43. }
  44. ?>
  45.  
Success #stdin #stdout #stderr 0.03s 25688KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Notice:  Undefined index: REQUEST_METHOD in /home/OLZaO1/prog.php on line 5