This is my setup:
- Windows XP SP3
- WampServer 2.0i
- PHP version 5.3.0
- Apache version 2.2.11
- MySQL version 5.1.36
- PEAR version 1.9.0
This is what we have to do:
- Load the pear console
- Login to the pear channel
- Services_Recaptcha-0.2.1 requires HTTP_Request2-0.4.1 which in turn requires Net_URL2-0.2.0 so we will install in this order: Net_URL2-0.2.0, HTTP_Request2-0.4.1, then Services_Recaptcha-0.2.1
- Test it is working
Step One can be further broken down into two steps:
- Open the windows command line
- Switch to the PHP directory
This is one way of doing it:
- click start
- click run
- type cmd.exe in the 'open' field
- click ok or press enter
2: Switch to the PHP directory.
This is the directory where php.exe is located. If you installed WampServer using default configurations then you will probably be going here: c:\wamp\bin\php\php5.3.0
On the command line type the following: cd c:\wamp\bin\php\php5.3.0
The prompt should now look like this c:\wamp\bin\php\php5.3.0
At this point it would be good to verify everything is going ok. Type 'pear' (without quotes) and hit enter. A list of pear commands should load.
This is what it looks like:
If this does not happen then check the following:
- Did you spell pear correctly? This is the most obvious mistake so rule this one out first.
- Are you in the right directory? Type 'dir' and a list of files should load. You know you are in the right directory if you see the following files:
- php.exe
- php.ini
- pear.bat
- PEAR
- Did you install PEAR (or did you install it correctly)? Go back and do it again
Step Two: Login to the pear channel
At the prompt just type the following: pear login
- Select '1' and enter a username
- Select '2' and enter a password
- Review and hit enter if everything is ok.
- You are logged in
Step Three: Installations
It's as simple as typing these three commands in succession:
- pear install pear/Net_URL2-0.2.0
- pear install pear/HTTP_Request2-0.4.1
- pear install pear/Services_Recaptcha-0.2.1
It would also be a good idea to check http://pear.php.net to make sure you are installing the most recent version of Services_Recaptcha and its dependencies.
Step Four: Test it is working
To test it is working we will use some test code. Just cut and paste the following code and save as recaptcha.php and put this file in your DocumentRoot (c:\wamp\www if you installed WampServer with default configuration)
This code comes from: http://code.google.com/p/services-recaptcha/wiki/RecaptchaExample2
Here is the code:
<?php /** * Include the Services_ReCaptcha class */ require_once 'Services/ReCaptcha.php'; // you must get your API keys here: // http://recaptcha.net/api/getkey $publicKey = 'your_public_key'; $privateKey = 'your_private_key'; // we instanciate our Services_ReCaptcha instance with the public key and the // private key $recaptcha = new Services_ReCaptcha($publicKey, $privateKey); // we are going to customize our Services_ReCaptcha instance $recaptcha->setOption('secure', true); // force the secure URL $recaptcha->setOption('theme', 'white'); // use the white theme $recaptcha->setOption('lang', 'fr'); // set language to french // alternatively we could have done: // $recaptcha = new Services_ReCaptcha($publicKey, $privateKey, true, array( // 'secure' => true, // 'theme' => 'white', // 'lang' => 'fr' // )); // or: // $recaptcha->setOptions(array('secure' => true, 'theme' => 'white', 'lang' => 'fr')); // we use a proxy, so we need to configure it $recaptcha->getRequest()->setConfig(array( 'proxy_host' => 'localhost', 'proxy_port' => 8118, )); // if the form was submitted if (isset($_POST['submit'])) { if ($recaptcha->validate()) { // the catpcha challenge response is ok, we display a message and exit echo "Challenge response ok !"; exit(0); } else { // if the captcha validation failed, instead of letting the captcha // display the error, we want to echo the error and exit echo $recaptcha->getError(); exit(1); } } // we display the html form ?> <html> <head> <title>recaptcha test</title> </head> <body> <form method="post" action=""> <?php echo $recaptcha; ?> <hr/> <input type="submit" name="submit" value="Ok"/> </form> </body> </html>
Get the Recaptcha Keys
Next we go to http://recaptcha.net/api/getkey and get a public and private key to insert into the script (around lines 10-11). For development purposes make global keys. In other words, we don't intend to use these keys in the real world and we don't want to set up new keys more than once for development purposes.
Load the page into your browser. This is what you should see:
That's it! You have successfully installed PEAR package Services_Recaptcha-0.2.1
No comments:
Post a Comment