# KClient PHP

pro business

KClient PHP allows connecting remotely to Keitaro via Click API.

# Getting KClient PHP

Open campaign settings, then Integration tab:


For the integration to work correctly, you need a parked domain with active HTTPS.

# Uploading kclient.php

After we have created our campaign, we need to connect to our remote site via SFTP.

Having connected, we need to go to the directory and find the site (page) index file for which we want to make the integration.

Create file index.php and paste the code at the beginning of the file (before <html> and DOCTYPE).


If you have index.html delete it or rename to index.php.

Checking for UTF-8 BOM

An important condition for adding and saving the file with the code of your site is the absence of a BOM-symbol in the Utf-8 encoding.

BOM (Byte Order Mark) is a symbol in the form of U + FEFF.

This can be done using a regular text editor:

We also need the client file itself. You can download it there:

Download it to the file and load it next to the index.php where we just inserted the integration code.

At this point, the main stage of integration is complete. Now, when you go to the site's main page, in the code of which we added the integration, you can see the Keitaro campaign we created.

You can check the client's work using the Traffic Log in the campaign. Go to an integrated site. The log must show the click and the action is taken (Redirect to the offer, Do nothing, etc.).

# Testing

Try to open your site, then open the campaign, and press Log. You must see information about your click:


If traffic log is turned of, you must turn it on and open the website again.

# Sending postbacks

To make postback, you need "subid" and saved to a session. It can be received with method $client->getSubid();. Example:

$_SESSION['subid'] = $client->getSubid();

Then, when you need to send postback, use a code:

$url = 'https://tracker.com/POSTBACK_KEY/postback?payout=100&status=sale&subid=' . urlencode($_SESSION['subid']);

See also:

If just need to generate a link to an offer, use $client->getOffer() method.


require_once dirname(__FILE__) . '/kclient.php';
$client = new KClient('https://domain_tracker/api.php?', 'wzbfwg3dxlmttkvt5v63mbw3x');
<a href="<?php echo $client->getOffer() ?>">CLICK!</a>

Make sure the stream uses Landing Pages and Offers as stream scheme.

To make a link to a specific offer, use offer_id parameter. Example:

<a href="<?php echo $client->getOffer(array('offer_id' => 123), '#');?>">LINK</a>

If the campaign can return empty offer, use second parameter to make a fallback link.


<a href="<?php echo $client->getOffer(null, 'https://google.com');?>">LINK</a>


# Debugging

First, you must want to turn on debug mode.

How to turn on debug mode?

If there are no clicks add to the end of integration code:


After $client->execute() and $client->executeAndBreak().

This will show the debug info on the page.

# Show content in specific places in the site

  1. Delete the lines $client->execute(); and $client->executeAndBreak();.

  2. Add $GLOBALS['client'] = $client;.

  3. Put the code in the necessary place <?php echo $GLOBALS['client']->getContent() ?>.

# Methods

Method Description
$client->sendAllParams() Passing parameters from an address bar
$client->forceRedirectOffer() Enables redirects to offers. If offer is chosen in the stream, it will be performed redirect to it. In other case, you must use getOffer()
$client->params('param1=c&param2=b') Passing parameters string
$client->param('extra_param_5', '123') Alternative method of passing a parameter
$client->sendUtmLabels() Passing utm-labels from the address bar
$client->debug() Displaying the debugging information
$client->currentPageAsReferrer() Send the current page address as a referrer
$client->keyword('QUERY') Using the "QUERY" value as a keyword
$client->execute() Executing Keitaro instructions with the continuation of the page code execution
$client->executeAndBreak() Executing Keitaro instructions with stoppage of the page execution. If the action "Do Nothing" is passed in the stream, tracker won't stop the page loading.
$client->getOffer() Returns the offer link. The campaign must contain streams with schema 'Offers'. In other case, you'll receive 'no_offer'. Use this method if you don't want to perform automatic redirect to offer.
$client->getBody() Get 'body' value
$client->getSubId() Returns SubId
$client->getHeaders() Get 'headers' value (array)
$client->isUnique(level) Uniqueness (level variations: stream, campaign, global)
$client->isBot() Bot status
$client->disableSessions() Turns off PHP session (without this cookie restoreFromSession won't work)
$client->restoreFromQuery() Catches query params _subid and _token without creating new click
$client->restoreFromSession() Restores previous click data from session without creating new click

# Error codes

  • [REQ_ERR: 400] - This response means that server could not understand the request because of response.
  • [REQ_ERR: 401] - The client must authenticate itself to get the requested response.
  • [REQ_ERR: 403] - The client does not have access rights to the content.
  • [REQ_ERR: 404] - The server can not find the requested resource.
  • [REQ_ERR: 405] - The request method is known by the server but has been turned off and cannot be used.
  • [REQ_ERR: 407] - The authentication is needed to be done by a proxy.
  • [REQ_ERR: 408] - Request timeout.
  • [REQ_ERR: 410] - The requested content has been permanently deleted from the server, with no forwarding address.
  • [REQ_ERR: 429] - The user has sent too many requests in a given amount of time.
  • [REQ_ERR: 500] - The server has encountered a situation it doesn't know how to handle.
  • [REQ_ERR: 501] - The request method is not supported by the server and cannot be handled.
  • [REQ_ERR: 502] - The server, while working as a gateway to get a response needed to handle the request, got an invalid response.
  • [REQ_ERR: 503] - The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded.
  • [REQ_ERR: 504] - The server is acting as a gateway and cannot get a response in time.
  • [REQ_ERR: 505] - The HTTP version used in the request is not supported by the server.
  • [REQ_ERR: UNSUPPORTED_PROTOCOL] - The URL you passed used a protocol that this cURL does not support.
  • [REQ_ERR: FAILED_INIT] - Very early initialization failed. This is likely to be an internal error or problem, or a resource problem where something fundamental couldn't get done at init time.
  • [REQ_ERR: BAD_URL] - The URL was not properly formatted.
  • [REQ_ERR: COULDNT_RESOLVE_PROXY] - The given proxy host could not be resolved.
  • [REQ_ERR: COULDNT_RESOLVE_HOST] - The given remote host was not resolved. Check DNS settings of the domain.
  • [REQ_ERR: COULDNT_CONNECT] - Cannot connect to the tracker. Check if server where Keitaro installed is up.
  • [REQ_ERR: PARTIAL_FILE] - A data transfer was shorter or larger than expected. Check Keitaro system log.
  • [REQ_ERR: READ_ERROR] - There was a problem reading a data
  • [REQ_ERR: OUT_OF_MEMORY] - A memory allocation request failed. You must increase memory_limit on the client server.
  • [REQ_ERR: OPERATION_TIMEDOUT] - The specified time-out period was reached according to the conditions.
  • [REQ_ERR: HTTP_POST_ERROR] - Internal post-request generation error.
  • [REQ_ERR: BAD_FUNCTION_ARGUMENT] - A function was called with a bad parameter.
  • [REQ_ERR: TOO_MANY_REDIRECTS] - There's an infinite redirects.
  • [REQ_ERR: GOT_NOTHING] - Nothing was returned from the server.
  • [REQ_ERR: SEND_ERROR] - Cannot send data to the tracker.
  • [REQ_ERR: RECV_ERROR] - Failure with receiving network data.
  • [REQ_ERR: BAD_CONTENT_ENCODING] - Unrecognized transfer encoding.
  • [REQ_ERR: SSL] - SSL error. You must check Cloudflare settings (section SSL).
  • [REQ_ERR: UNKNOWN] - Unknown error. Check Keitaro logs.

# KClient PHP FAQ

Why the page shows status 500?

Add after <?php:

ini_set('display_errors', 'on');

It must show the error message.

Why HTTP-redirect doesn't work?

File index.php might contain a BOM header.

Search for Save UTF-8 without BOM in your editor.

How to filter bots?

For the integration to work, we need a remote site with FTP access and a created campaign in Keitaro.

First, let's create our campaign:

We create two streams. The first stream has the "Do Nothing" action and the "Bot" filter. That will allow us to leave bots on the website.

We will use the second stream for our clients. Here, we can add a link to a redirect, an offer, and a landing page. This all depends on your traffic funnel.

This setting will allow us to leave bots on the site and direct clients to wherever we want.

How to integrate KClient PHP with WordPress

Use WordPress plugin.

How to leave specific visitors on the site?




How to send title as a keyword?

You need to learn how to get title in php scripts. You need to send the keyword with $client->keyword('...') method:


$myTitle - is the example of how thw variable content is transferred as a keyword.

How to leave specific users on the site?

Use action "Do Nothing" in the stream.

How to just check if visitor is a bot?

Use method $client->isBot(). Example:

if ($client->isBot()) {
   echo 'bot';
} else {
   echo 'not bot';
How to insert the path to kclient.php if there are folders

Check your site directory and put an obsolete path:

require '/path_to_the_website/kclient.php';
How to get a subid on secondary pages

The subid content is saved into a session:


Please use the following piece of code in your scripts:

session_start(); // if the session wasn't used earlier it's better to launch it.
$data = array(
 'sub1' => $_SESSION['sub_id'],
 'name' => $_POST['name'],
How to use Click Client on inner pages?

Enable Click Client on an inner page adding $client->restoreFromSession(); :

require_once dirname(__FILE__) . '/kclient.php';
$client = new KClient('https://..../api.php?', 'TOKEN');


Paste that code to create an offer link:

<a href="<?php echo $client->getOffer()">offer link</a>