# KClient PHP

Important!

Available only in Professional and Business licenses

KClient PHP is a PHP client which helps to integrate third-party php-websites.

# Features

  • Passing information about the current visitor to Keitaro.
  • Passing parameters from the address bar.
  • Processing and execution of Keitaro instructions: displaying a text, executing a redirect.

# KClient PHP FAQ

This is example to use offer link in the page template:

<?php
require_once 'kclick_client.php';
$client = new KClickClient('http://example.con/api.php', 'token');
$offerLink = $client->getOffer();
?>
<html>
...
<body>
<a href="<?php echo $offerLink ?>">CLICK!</a>
</body>
</html>

You have to assign offers and one landing page to the stream.

How to Make Link for Particular Offer

<?php
require_once 'kclick_client.php';
$client = new KClickClient('http://example.con/api.php', 'token');
?>
<a href="<?php echo $client->getOffer(['offer_id' => 123]) ?>">CLICK!</a>

# How to prevent a website from loading after the code

Replace

$client->execute();

with

$client->executeAndBreak();

# How to Send Postbacks

To get your postback your, add new affiliate network. You'll get there the postback URL.

On your website, call this code to send a postback

$url = 'http://tds/POSTBACK_KEY/postback?payout=100&status=sale&subid=' . urlencode($_SESSION['sub_id']);
file_get_contents($url);

# How to Show the Content From the Stream in the Specific Place

Instead of using $client->execute(); use $client->getContent(). Example:

<?php echo $client->getContent() ?>

# How to Integrate KClient PHP with Wordpress

Use WordPress plugin.

# How to Leave Users on the Website

Use action “Do Nothing” in the stream.

# 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:

$client->keyword($myTitle);

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

# How to solve issues with Click Client

First of all check if the clicks get into the tracker. Check the traffic log and campaign's Clicks Report.

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

$client->showLog();

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

This will show the debug info on the page.

If there's no log add the following before the integration code (after <?php):

ini_set('display_errors', 'on');
error_reporting(7);

# How to check if Keitaro defines the user as a bot

/*
client incialization code
*/
if ($client->isBot()) {
   echo 'bot';
} else {
   echo 'not bot';
}

# Why there's no offer redirect

By default, an offer is added as a link with $client->getOffer(). Add a line so the offer redirect is performed:

$client->forceRedirectOffer();

# How to insert the path to kclick_client.php if there are folders

Check your website directory and put an obsolete path:

require '/path_to_the_website/kclick_client.php';
...

# Why is there a php-code on a website and it's not performed

  1. Make sure the index file is with php extension.
  2. The code itself has tags:
<?php
....code....
?>

# Error: TOO_MANY_REDIRECTS in a browser

Your stream sends visitors to the website where click api client is installed and gets redirected again and again. Edit the stream with website redirect. Change scheme to Action and select Do nothing.

# How to Perform Offer Redirect

By default Click Client uses offers as link, that you can get by using $client->getOffer(). To make it perform redirect, add this:

$client->forceRedirectOffer();

# How to get a subid on secondary pages

The subid content is saved into a session:

$_SESSION['sub_id'];

You can 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 track the domains which call the campaign

You can send domain name as a campaign parameter:

$client->param('sub_id_1', $_SERVER['HTTP_HOST']);

# How to Prevent Collecting Multiple Clicks?

Add these line to the integration code:

$client->restoreFromSession();

It will look like these:

$client = new KClickClient(...);
$client->restoreFromSession();
...
$client->execute();

# How to use Click Client on inner pages

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

<?php
require_once dirname(__FILE__) . '/kclick_client.php';
$client = new KClickClient('http://..../api.php?', 'TOKEN');

$client->restoreFromSession();

Now you can call the same methods without creating a new click:

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

# Request error codes

  • [REQ_ERR: 400] - This response means that server could not understand the request due to invalid syntax

  • [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 disabled 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] - Failed to connect to host or proxy. 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] - When following redirects, client hit the maximum amount

  • [REQ_ERR: GOT_NOTHING] - Nothing was returned from the server

  • [REQ_ERR: SEND_ERROR] - Failed to send network data

  • [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.

Last Updated: 7/23/2020, 6:31:23 AM