Configuration

Passing IPs (Using Cloudflare etc.)

In case you are using some service, such as CloudFlare, that is between the user and your actual servers, the ip detected in backend_loader.php may be detected as invalid. This might cause the clicks or impressions of the ads to be registered incorrectly. To fix this, you can substitute the $_SERVER[“REMOTE_ADDR”] passed to UserEnvironment class in backend_loader.php with the correct value passed on by your caching/proxying service.

In the case of Cloudflare we would pass the $_SERVER[“HTTP_CF_CONNECTING_IP”] parameter. An example shown below.

isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR']

Once this is done our UserEnvironment will look like the following:

$userEnvironment = new UserEnvironment(
    isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'],
    isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : null,
    isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null,
    isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null,
    isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null
);

When using another service such Apache or NGINX we can use isset($_SERVER[‘HTTP_X_REAL_IP’]) ? $_SERVER[‘HTTP_X_REAL_IP’] : $_SERVER[‘REMOTE_ADDR’] as shown in the following:

$userEnvironment = new UserEnvironment(
    isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $_SERVER['REMOTE_ADDR'],
    isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : null,
    isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null,
    isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null,
    isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null
);

We can now re-run diag.php, if this was causing the IP Detection test to fail we should now have successful results.

Logfile

This was an optional configuration during Automatic Installation. If you wish to log request time outs and other errors, a writable log file can be created. In this example the logfile has been put into the same directory as our other NeverBlock files.

configuration_2

Once this file is created (remember to ensure it’s writable) we will update the backend_loader.php to set the path. At the top of the file ‘LOGFILE’ will be set to NULL and should be set to the new logfile like so: Update this to the set the path:

define('LOGFILE', 'logfile');

Once this is done we can re-run the diag.php. If the file was created and path set correctly we will now see the following.

configuration_3

Caching

This was an optional configuration during Automatic Installation. Caching can significantly improve response times for ads. If you do not have APC or XCache, which are supported by backend_loader.php by default, it is recommended to set up a file cache. For this you need to set up a directory writable by php and set its path as a value for the WRITABLE_PATH constant in the backend_loader.php. If this constant is set - file cache will be used by default instead any other caches (even if you have APC or XCache).

define('WRITABLE_PATH', '/path/to/my/writeable_folder');

Identification keys

If you have used the Automatic Installation this has already been done during installation. These keys are used for encryption to prevent tampering with banner urls. It is strongly recommended to change values for both KEY_1 and KEY_2 in the backend_loader.php to some unique strings.

define('KEY_1', "t8Sn7cvBv2n8duxUyrtUxqd6i+gAywzoNo72ItPEtdU=");
define('KEY_2', "zCeopESQfMDIVekZkytm52lbdnQ2iC2RgLuh3RAhexU=");

Cookies

Cookies are used to make sure NeverBlock working as expected.

  • yuo1 - the default name of this cookie is yuo1, and this name can be configured in frontend_loader.js. This cookie can also be disabled by setting no_cookie: true.

  • zone-closed- - This cookie ensures that the zone stays closed if the user has closed it with adBlock enabled and then disabled the adBlock.

Configuring constants

There are some constants defined in backend_loader.php. It’s recommended to keep them as they are, but in some cases it can be useful to change some of the configurations.

  • CONNECT_TIMEOUT_MS - the connection timeout in milliseconds used for curl/fsock requests.
  • REQUEST_TIMEOUT_MS - the whole request timeout in milliseconds (also includes time from CONNECT_TIMEOUT_MS) used for curl/fsock requests.
  • LOGFILE - a path to a writable file to log the messages, like some errors and cases when requests time out.
  • ALLOW_MULTI_CURL - when possible, script tries to use curl_multi_exec. If this is a burden on cpu - this can be turned off.

XCache, APC, File cache settings:

  • WRITABLE_PATH - path to writable directory, that will contain cache files. (if this is set - file cache will become default cache to use)
  • CACHE_INTERVAL_BANNERS - cache lifetime for banner images (in seconds), if set to 0 images will NOT be cached.
  • CACHE_INTERVAL_SCRIPTS - cache lifetime for for javascripts, if set to 0 they will NOT be cached.
  • CACHE_KEYS_LIMIT_BANNERS - the limit for number of allowed banner images to store in cache (to not overuse publisher resources), if set to 0 there will be no limit, so all the images will be cached.

If you setup some apache/nginx rewrite rules to access backend_loader.php through some other URIs:

  • LINK_URL_PREFIX - if is set, this will become the new URI for click links on frontend (the hash of url for redirection appended to it)
  • BANNER_URL_PREFIX - if is set, this will become the new uri for banner images on frontend (the hash for specific banner appended to it)
  • KEY_1 - secret key to prevent tampering with banner urls (they are now passed back to backend loader in request)
  • KEY_2 - secret key to prevent tampering with banner urls (they are now passed back to backend loader in request)