Services_ReCaptcha
[ class tree: Services_ReCaptcha ] [ index: Services_ReCaptcha ] [ all elements ]

Class: Services_ReCaptcha

Source Location: /Services_ReCaptcha-1.0.3/Services/ReCaptcha.php

Class Overview

Services_ReCaptcha_Base
   |
   --Services_ReCaptcha

PHP5 interface to the reCATCHA API.


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 2008-2009 David Jean Louis

Variables

Methods


Inherited Variables

Inherited Methods

Class: Services_ReCaptcha_Base

Services_ReCaptcha_Base::__construct()
Constructor, you must pass a valid public and private API key, and optionnaly an array of options.
Services_ReCaptcha_Base::getHTML()
Returns the corresponding HTML code.
Services_ReCaptcha_Base::getOption()
Returns an option from Services_ReCaptcha::$options.
Services_ReCaptcha_Base::getOptions()
Returns the Services_ReCaptcha::$options array.
Services_ReCaptcha_Base::setOption()
Sets an option in Services_ReCaptcha::$options and returns the current Services_ReCaptcha_Base instance.
Services_ReCaptcha_Base::setOptions()
Sets a number of options at once in Services_ReCaptcha::$options and returns the current Services_ReCaptcha_Base instance.
Services_ReCaptcha_Base::__toString()
Returns the corresponding HTML code, this is a "magic" shortcut to the getHTML() method.

Class Details

[line 56]
PHP5 interface to the reCATCHA API.

reCAPTCHA is a freely available CAPTCHA implementation. It distinguishes humans from computers.

In order to use reCAPTCHA, you need a public/private API key pair. This key pair helps to prevent an attack where somebody hosts a reCAPTCHA on their website, collects answers from their visitors and submits the answers to your site. You can sign up for a key on the reCAPTCHA Administration Portal



[ Top ]


Class Variables

$apiSecureURL =  'https://www.google.com/recaptcha/api'

[line 74]

The reCAPTCHA API secure URL, this is URL is used by default when the script is running on an https host or when you force it via the 'secure' option.
  • Access: public

Type:   string


[ Top ]

$apiURL =  'https://www.google.com/recaptcha/api'

[line 65]

The reCAPTCHA API URL.
  • Access: public

Type:   string
Overrides:   Array


[ Top ]

$apiVerifyURL =  'http://www.google.com/recaptcha/api/verify'

[line 81]

Url of the ReCaptcha verify API.
  • Access: public

Type:   string


[ Top ]

$error =

[line 90]

The error code used to display the error message in the captcha.

Type:   string


[ Top ]

$options = array(
        'secure'              => false,
        'xhtml'               => true,
        'theme'               => null,
        'lang'                => null,
        'custom_translations' => null,
        'custom_theme_widget' => null,
        'tabindex'            => null,
    )

[line 113]

Options to customize the html, the url and the look and feel of the captcha.

Available options are:

  • secure: whether to force the ssl url (default: false);
  • xhtml: whether the html should be xhtml compliant (default: true);
  • theme: string, defines which theme to use for reCAPTCHA (default: red);
  • lang: string, one of the supported language codes (default: en);
  • custom_translations: array, se this to specify custom translations of reCAPTCHA strings (default: null).
  • custom_theme_widget: string, the ID of a DOM element (default: null);
  • tabindex: integer, the tabindex for the reCAPTCHA text area.
For a full documentation of theses options please consult the API documentation.


Type:   array
Overrides:   Array


[ Top ]

$request =

[line 143]

The HTTP_Request2 instance.

You can customize the request if you need to (ie: if you use a proxy) with the get/setRequest() methods, for example:

  1.  require_once 'Services/ReCaptcha.php';
  2.  
  3.  $recaptcha = new Services_ReCaptcha('pubkey''privkey');
  4.  $recaptcha->getRequest()->setConfig(array(
  5.      'proxy_host' => 'localhost',
  6.      'proxy_port' => 8118,
  7.  ));


Type:   HTTP_Request2


[ Top ]



Method Detail

__construct (Constructor)   [line 158]

void __construct( string $pubKey, string $privKey, [array $options = array()])

Constructor, you must pass a valid public and private API key.

Overrides Services_ReCaptcha_Base::__construct() (Constructor, you must pass a valid public and private API key, and optionnaly an array of options.)

Parameters:

string   $pubKey   —  The public API key (mandatory)
string   $privKey   —  The private API key (mandatory)
array   $options   —  An array of options (optional)

[ Top ]

getError   [line 344]

string getError( )

Returns the current error code.

[ Top ]

getHTML   [line 214]

string getHTML( )

Returns the HTML code to insert into your form.

Instead of this method you can use the __toString() magic method to get the HTML code, for example:

  1.  require_once 'Services/ReCaptcha.php';
  2.  
  3.  $recaptcha = new Services_ReCaptcha('pubkey''privkey');
  4.  // both are equivalents:
  5.  $html $recaptcha->getHTML();
  6.  $html = (string) $recaptcha;


Overrides Services_ReCaptcha_Base::getHTML() (Returns the corresponding HTML code.)
[ Top ]

getRequest   [line 377]

HTTP_Request2 getRequest( )

Returns the HTTP_Request2 instance, if it's not yet set it is instanciated on the fly.

[ Top ]

getURL   [line 174]

string getURL( [string $path = 'challenge'])

Returns the URL of the script or iframe src attribute.
  • Return: The URL of the script or iframe src attribute
  • Access: public

Parameters:

string   $path   —  Set this to "noscript" to get the iframe URL instead of the script URL

[ Top ]

setError   [line 361]

Services_ReCaptcha setError( string $error)

Sets the error code to display in the captcha and returns the current Services_ReCaptcha instance.

Parameters:

string   $error   —  The error message

[ Top ]

setRequest   [line 397]

Services_ReCaptcha setRequest( HTTP_Request2 $request)

Sets the HTTP_Request2 instance and returns the current Services_ReCaptcha instance.

Parameters:

HTTP_Request2   $request   —  The request to set

[ Top ]

validate   [line 277]

bool validate( [string $challenge = null], [string $response = null], [int $ip = null])

Validates the challenge response typed by the user and returns true if the challenge response is ok or false otherwise.

You can explicitely pass the challenge, response and ip values if for some reason you need to do so.

  • Return: Whether the challenge response is valid or not
  • Throws: Services_ReCaptcha_HTTPException When the server returns an error response
  • Throws: Services_ReCaptcha_Exception When the request cannot be sent
  • Access: public

Parameters:

string   $challenge   —  Value of the challenge field, if not given, the method will look for the value in $_POST array
string   $response   —  Value of the response field, if not given, the method will look for the value in $_POST array
int   $ip   —  The user IP address, if not given, the method will use $_SERVER['REMOTE_ADDR']

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:43:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.