Advertisement
PJH

reCAPTCHA example

PJH
Apr 26th, 2012
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <html>
  2. <body> <!-- the body tag is required or the CAPTCHA may not show on some browsers -->
  3. your HTML content
  4.  
  5.  
  6. <?php
  7.     $publickey = "XXX";
  8.     $privatekey = "YYY";
  9.     require_once('recaptchalib.php');
  10.  
  11.     if (isset($_POST["recaptcha_response_field"])){
  12.         echo "<pre>";
  13.         print_r($_POST);
  14.         require_once('recaptchalib.php');
  15.         $resp = recaptcha_check_answer ($privatekey,
  16.                                         $_SERVER["REMOTE_ADDR"],
  17.                                         $_POST["recaptcha_challenge_field"],
  18.                                         $_POST["recaptcha_response_field"]);
  19.         print_r($resp);
  20.         print_r($_SERVER);
  21.     }
  22. ?>
  23.  
  24. <form method="post" action="recaptcha.php">
  25. <?php echo recaptcha_get_html($publickey); ?>
  26. <input type="submit" />
  27. </form>
  28.  
  29. more of your HTML content
  30. </body>
  31. </html>
  32.  
  33. <!-- Example output for valid entry
  34.  
  35. Array
  36. (
  37.     [recaptcha_challenge_field] => 03AHJ_VuvHgC572BKLlgNYGK3_6XxQHRI4gakBrWRC9wgenmWDDMWJngNMt-33gV0N9g0AD6qMPnYst38yQ_X2WQkz13ffHLrrU7fmjmvuH42M00T6VH3lZ4QM5VoZb7k5zQChr_vgeuUo9GerHwASwP2mp5hE8ZBI7Q
  38.     [recaptcha_response_field] => iitingn 26
  39. )
  40. ReCaptchaResponse Object
  41. (
  42.     [is_valid] => 1
  43.     [error] =>
  44. )
  45. Array
  46. (
  47.     [UNIQUE_ID] => T5lcRn8AAAEAABCSU-QAAAAH
  48.     [HTTP_HOST] => localhost
  49.     [HTTP_USER_AGENT] => Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0
  50.     [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  51.     [HTTP_ACCEPT_LANGUAGE] => en-gb,en-us;q=0.8,en;q=0.5,fr;q=0.3
  52.     [HTTP_ACCEPT_ENCODING] => gzip, deflate
  53.     [HTTP_DNT] => 1
  54.     [HTTP_CONNECTION] => keep-alive
  55.     [HTTP_REFERER] => http://localhost/recaptcha.php
  56.     [CONTENT_TYPE] => application/x-www-form-urlencoded
  57.     [CONTENT_LENGTH] => 226
  58.     [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
  59.     [SERVER_SIGNATURE] =>
  60. Apache/2.2.17 (PCLinuxOS 2011/PREFORK-1pclos2011) Server at localhost Port 80
  61.  
  62.  
  63.     [SERVER_SOFTWARE] => Apache/2.2.17 (PCLinuxOS 2011/PREFORK-1pclos2011)
  64.     [SERVER_NAME] => localhost
  65.     [SERVER_ADDR] => 127.0.0.1
  66.     [SERVER_PORT] => 80
  67.     [REMOTE_ADDR] => 127.0.0.1
  68.     [DOCUMENT_ROOT] => /var/www/html
  69.     [SERVER_ADMIN] => root@localhost
  70.     [SCRIPT_FILENAME] => /var/www/html/recaptcha.php
  71.     [REMOTE_PORT] => 50032
  72.     [GATEWAY_INTERFACE] => CGI/1.1
  73.     [SERVER_PROTOCOL] => HTTP/1.1
  74.     [REQUEST_METHOD] => POST
  75.     [QUERY_STRING] =>
  76.     [REQUEST_URI] => /recaptcha.php
  77.     [SCRIPT_NAME] => /recaptcha.php
  78.     [PHP_SELF] => /recaptcha.php
  79.     [REQUEST_TIME] => 1335450694
  80. )
  81. -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement