API Main Help

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 

Requirements:

  • PHP 4.3 and above.
  • CURL support.

There are two ways to manually use the service:

  1. You can create a function to send a message by using PHP extension CURL. The example you can see in this article: https://cleantalk.org/help/api-without
  2. Or can hook CleanTalk API and use it. What will be discussed in this article. We highly recommend you to use this option. Because it is easier to implement, you just connect the class and you can use it anywhere in your code, plus it contains a built-in function for input validation, checks messages for spam and parses the received message. You can download API from Github.com (link is at the bottom of article).

In order to start using the CleanTalk API you need to connect it to your site:

 

Download the CleanTalk library here. The library folder must be placed in the same path as the php file.

Also, you can install the library via composer.

 

session_start(); //Sessions is required
 
require_once (dirname(__FILE__) . '/lib/Cleantalk.php');
require_once (dirname(__FILE__) . '/lib/CleantalkRequest.php');
require_once (dirname(__FILE__) . '/lib/CleantalkResponse.php');
require_once (dirname(__FILE__) . '/lib/CleantalkHelper.php');
 

Next, you need to set the access key and the address of the request to the service:

You can get a key here: https://cleantalk.org/register?platform=api.

$config_url = 'http://moderate.cleantalk.org'; //server adress
$auth_key = 'access_key_here'; //access key

Create a new instance of a class which will store the query parameters:

$ct_request = new CleantalkRequest();

The following code should be modified automatically for each request:

$ct_request->auth_key = $auth_key; //Access key from the previously set variable
$ct_request->message = 'stop_word'; //Message for check
$ct_request->method_name = 'check_message'; //Check method default is check_message also exist check_newuser, send_feedback
$ct_request->sender_email = 'stop_email2@example.com'; //Email to check.
$ct_request->sender_nickname = 'John Dow'; //Nickname for check
$ct_request->example = str_repeat('Just text ', 10);
$ct_request->agent = 'php-api'; //Name of exstension. Must be without changes.
$ct_request->sender_ip = '178.32.183.43'; //IP address for check
$ct_request->js_on = 1; //JavaScript check check flag
$ct_request->submit_time = 12; //Time of filling the form

If you have not implemented check for JavaScript and for some reason you can't do, leave $ct_request->js_on = 1; . But we don't recommend to do so, because it's important part of checking spam bots. You can learn more about it here: https://cleantalk.org/help/api-without

Sending a request:

$ct = new Cleantalk();
$ct->server_url = $config_url;

Checking result and printing server's commentary:

$ct_result = $ct->isAllowMessage($ct_request);
if ($ct_result->allow == 1) {
echo 'Comment allowed. Reason ' . $ct_result->comment;
}
else {
echo 'Comment blocked. Reason ' . $ct_result->comment;
}

You can add more parameters to $ct_request:

  • sender_nickname - sender nickname for spam checking;
  • sender_info - any additional information about user (must be coded in JSON).

You can find a workable example and download API here: 

https://github.com/CleanTalk/php-antispam

We recommend you to learn more about each of the check methods:

If you still have questions you can always ask our Tech support by creating a ticket https://cleantalk.org/my/support.

 

 

Was this information helpful?

No

Yes




Perhaps it would also be interesting