Skip to content

Instantly share code, notes, and snippets.

@RobertCalise
Created June 16, 2020 15:25
Show Gist options
  • Save RobertCalise/30a4c5498886e257ce8bc73205b63b1b to your computer and use it in GitHub Desktop.
Save RobertCalise/30a4c5498886e257ce8bc73205b63b1b to your computer and use it in GitHub Desktop.
Infusionsoft Custom Domain Affiliate Redirect Script

How to use this script

If you would like your Infusionsoft affiliate links to look like this:

https://yourdomain.com/refer/?w=ABC&p=123&a=XYZ

Create a directory on your website (for the example above, refer). In that directory, copy the code provided in this gist into a file called index.php.

Make sure you change the app_name and default_url variables in the script to reflect your own Infusionsoft application. So, for example, if your website is https://mywebsite.com and you log into Infusionsoft at https://xyz123.infusionsoft.com, then the beginning of this script should look like:

<?php

    // What is the Infusionsoft app name (the part that comes before '.infusionsoft.com')
    $app_name = 'xyz123';

    // Where should this script redirect if no affiliate variables are set?
    $default_url = 'https://mywebsite.com';
    
<?php
// What is the Infusionsoft app name (the part that comes before '.infusionsoft.com')
$app_name = 'abc123';
// Where should this script redirect if no affiliate variables are set?
$default_url = 'https://google.com/';
/*
* NOTE: Do not edit below this line unless you know what you're doing.
*/
function input_with_default($key, $default = false) {
// If a variable is set and not empty, return it.
if(isset($_GET[$key]) && !empty($_GET[$key])) {
return $_GET[$key];
}
// Otherwise, return default.
return $default;
}
$code = input_with_default('w', false);
$affiliate = input_with_default('p', false);
$ad = input_with_default('a', '');
// Only continue if $code and $affiliate are set.
// Otherwise, redirect to default URL.
if (!$code || !$affiliate) {
header('Location: '.$default_url);
exit;
}
// Construct link and remove trailing slash if ad is blank. Redirect.
$ref_link = rtrim('https://'.$app_name . '.infusionsoft.com/go/' . $code . '/' . $affiliate . '/' . $ad, '/');
header('Location: '.$ref_link);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment