API Main Help
Requirements:
- PHP 4.3 and above.
- CURL support.
There are two ways to manually use the service:
- 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
- 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:
- check_message - Post/commentary check.
- check_newuser - Registrations check.
- send_feedback - Send feedback to CleanTalk.
- spam_check - mass check for IPs, emails for spam activity.
- backlinks_check - mass check for backlinks in spam comments.
- Nginx Anti-Spam Module - check all POST requests for spam
- Universal Anti-Spam plugin - this plugin can be installed on any custom websites or CMS.
If you still have questions you can always ask our Tech support by creating a ticket https://cleantalk.org/my/support.
It would also be interesting
- The Real Person Badge | CleanTalk Anti-SpamThe Real Person Badge A benchmark system for WordPress that separates real users from bots. The...
- Spam Check API - API Method spam_checkAPI Method "spam_check" Common description Method's get parameters Response Explanation Multiple...
- How CleanTalk Anti-Spam Works. Manuals, Questions and Answers.CleanTalk Help Manuals, Questions and Answers Anti-Spam Service Premium Notice is still shown...