Custom PHP Conditions

Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don’t provide support for code customizations or 3rd party development.

Custom PHP Publishing Conditions give you the opportunity to display your box for virtually any occassion you can think of. The only thing stopping you is having the PHP knowledge to code it and how far you are willing to go.

With Custom PHP Publishing Conditions you can get all the data available in the variables, URLs and even the database. Then you can do all kinds of checks on these data.

The main point of Custom PHP Publishing Conditions is that you always need to return either a TRUE or a FALSE value. For TRUE the condition is valid and vice versa. Here’s an example:

if ($variable == 'value') {
   return true;
} else {
   return false;
}

Or written in a more compact way:

return ($some_variable == 'some value');

Below are a (growing) collection of ready-to-use PHP conditions scripts. You can also use these as examples and starting-point to create your own custom scripts.

Assign to certain (parts of) email addresses

// Comma separated list of (parts of) email addresses
$emails = '@yahoo.com,@hotmail.com';

// Do not edit below
$pass = 0;
foreach(explode(',', $emails) as $email) {
    if (!(strpos($user->email, $email) === false)) {
        $pass = 1;
        break;
    }
}
return $pass;

Assign to specific IP addresses

The IP Condition is available as a standalone condition.

// Comma separated list of IP addresses
$ips = '111.111.111.111,222.222.222.222';

// Do not edit below
return (in_array($_SERVER['REMOTE_ADDR'], explode(',',$ips)));

Assign to certain domain referer

The Referrer Condition is available as a standalone condition.

// Comma separated list of allowed domains
$domains = "facebook.com,twitter.com";

// Do not edit below
$referer = isset($_SERVER['HTTP_REFERER']) ? parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) : false;

if ($referer)
{
	$domain = str_ireplace("www.", "", $referer);
	return (in_array($domain, explode(',', $domains)));
}
Was this helpful?