Skip to content

adeto-network/adeto-php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adeto SDK for PHP

Welcome to Adeto PHP SDK. This repository contains Adeto's PHP SDK and samples for REST API.

Prerequisites

  • PHP 5.3 or above
  • json extension must be enabled

Please Note

Before getting started, you need to have a Publisher Key and a Secret Key in order to send requests to the API server. These will be delivered to Adeto Publishers after signing-up.

Show a Captcha

To show the Adeto Captcha in your forms, first you need to add adeto.js in the HEAD section of your page.

<script type="text/javascript" src="https://cdn.adeto.ir/js/adeto.js" async></script>

Then, where you want to show the captcha image, simply add a DIV with the id of adeto:

<div id="adeto" data-publisherkey="YOUR_PUBLISHER_KEY" data-lang="fa"></div>

In the line above, you need to replace YOUR_PUBLISHER_KEY with your own Publisher Key. Also if you want to show the Captcha in English language for your foreign users, you can change data-lang to en.

Verify a Captcha

To verify that if the user has entered the right text or not, we need to send a new request to the API server. In your form where you're showing the Adeto Captcha, 3 inputs are automatically generated:

  • adetoImageName
  • adetoHash
  • adetoUserInputValue

So wherever you are posting your form, these values will be also posted. for example if your form action is verify.php, when the user submits the form that contains Adeto Captcha, these 3 variables are also posted to verify.php. now in verify.php:

/**
 * require AdetoSDK.php class
 */
require_once 'src/AdetoSDK.php';

try {

    /**
     * Instantiate our object
     */
    $adeto = new Adeto($_SERVER['REQUEST_METHOD']);

    /**
     * Replace YOUR_PUBLISHER_KEY with your own publisher key
     */
    $adeto->publisherKey = "YOUR_PUBLISHER_KEY";

    /**
     * Replace YOUR_SECRET_KEY with your own secret key
     */
    $adeto->secretKey = "YOUR_SECRET_KEY";

    /**
     * Setting variables we need to verify a Captcha
     * Variables we need:
     * adetoImageName, adetoHash, adetoUserInputValue
     * These inputs are generated automatically in our Captcha div.
     *
     * This function checks if we have received all the needed variables
     * and throws an exception if some variables are not present
     */
    $adeto->checkIfReceivedAllVariables($adeto->method);

    /**
     * adetoImageName
     */
    $adeto->imageName = $_POST['adetoImageName'];

    /**
     * adetoHash
     */
    $adeto->hash = $_POST['adetoHash'];

    /**
     * adetoUserInputValue
     */
    $adeto->userInputValue = $_POST['adetoUserInputValue'];

    /**
     * Optional custom id if you have sent your request using a custom id
     * If you have not sent your request with a customId just ignore this
     * $adeto->customId = 8;
     */

    /**
     * Sending verification request using post() method
     */
    $results = $adeto->verify()->post();

    /**
     * In the example above, we used post() method. a curl() method is also available
     * So you can also use curl(), example:
     * $results = $adeto->verify()->curl();
     */

    /**
     * Results as JSON
     */
    $results = json_decode($results);

    /**
     * The final results
     * It's whether 'true' or 'false'
     */
    if ($results->status == 'true')
    {
        echo 'Captcha was RIGHT ;-)';

    } else {

        echo 'Captcha was WRONG :(';

    }

    /**
     * If there is an error in your request, you can get it using:
     * echo $results->message;
     * also var_dump($results) might help sometimes
     */

} catch (Exception $e) {

    echo 'Error: ' . $e->getMessage();

}

Also in this reposiotry you will find a working example of pages to show a captcha/verify a captcha.

More help

License

Read License for more licensing information.