Tracking

<?php

$nocURL =  isset($_GET['nocurl']) ? 1 : 0;
$cURL =  in_array('curl', get_loaded_extensions()) ? 1 : 0;

// release number
define('MT_RELEASE', '1.3.100');
define('MT_CURL_OK', ($cURL && !$nocURL));
define('MT_TIMEOUT', 10);
define('MT_ERR', !empty($_GET['err']));
define('MT_RES', !empty($_GET['res']));

if (isset($_GET['mtnotrk'])) {
	die();
}

// report errors if err variable is in query string
if (MT_ERR) {
	error_reporting(E_ALL);
	ini_set('display_errors', 'On');
}
else {
	error_reporting(0);
	ini_set('display_errors', 'Off');
}

// the deployed script must always be renamed before using it
if (basename(__FILE__) == 'mytracking.php') {
	die('For your safety: you really should change the name of this file');
}

// is it a test call?
if (!empty($_GET['test'])) {
    header("Content-type: text/plain");
	print "OK: ".MT_RELEASE."\r\nTRKAPI: ".gethostbyname('trkapi.com');
	die();
}

// retrieve query string values
$hop = isset($_GET['hop']) ? $_GET['hop'] : '';

if ($hop) {
	$parts = explode("/", $hop);
	$url = base64url_decode(end($parts));	
	if (parse_url($url, PHP_URL_SCHEME)) {
		process_content(retrieve_content(calculate_url($hop), $url));
		exit;
	}
}

process_content(retrieve_content(calculate_url($hop)));
exit;


// functions

function base64url_decode($data) {
	return base64_decode(strtr($data, '-_', '+/'));
}

function calculate_url($link) {
    $returnurl = '';
    if ($link == '') {
        $returnurl = 'http://trkapi.com/mytrackingok.gif';
    } else if ((preg_match("/.+/", $link))) {
          $src = array('/m/', '/r/', '/l/');
          $rpl = array('', '/', '/');
          $link = str_replace($src, $rpl, $link);
          $returnurl = 'http://trkapi.com/' . $link;  // 2.0 format
    }
    return $returnurl;
}


function retrieve_content($url, $fallback = "/?mtnotrk=1") {
    $response = '';
	$mt_errstr = '';
	$agent = 'MyTracking/'.MT_RELEASE;
	$protocol = isset($_SERVER['HTTPS']) ? "https://" : "http://";
	$port = '';
	if ($_SERVER['SERVER_PORT'] != '80' && $_SERVER['SERVER_PORT'] != '443') {
		$port = ":".$_SERVER['SERVER_PORT'];
	}	
	$refr = $protocol.$_SERVER['HTTP_HOST'].$port.$_SERVER['SCRIPT_NAME'];
    if ($url != '') {
        if (MT_CURL_OK) {        
  		    $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_HEADER, 1);
			if (MT_RES && defined('CURLOPT_RESOLVE')) {
				curl_setopt($ch, CURLOPT_RESOLVE, array("trkapi.com:80:199.187.175.16"));
            }
			curl_setopt($ch, CURLOPT_USERAGENT, $agent);
			curl_setopt($ch, CURLOPT_REFERER, $refr);
			curl_setopt($ch, CURLOPT_TIMEOUT, MT_TIMEOUT);
  		    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  		    if (!$response = curl_exec($ch)) {
				$mt_errstr = curl_errno($ch).' '.curl_error($ch);
			}
  		    curl_close($ch);
  	    }
  	    else {
			$parts = parse_url($url);
			$scheme = isset($parts['scheme']) ? $parts['scheme'] : 'http';
			$host = isset($parts['host']) ? $parts['host'] : 'trkapi.com';
			$port = isset($parts['port']) ? $parts['port'] : 80;
			$path = isset($parts['path']) ? $parts['path'] : '/';
			$query = isset($parts['query']) ? '?'.$parts['query'] : '';
			if ($fp = fsockopen ($host, $port, $errno, $errstr, MT_TIMEOUT)) {
				fputs ($fp, "GET $path$query HTTP/1.0\r\nHost: $host\r\nUser-Agent: $agent\r\nReferer: $refr\r\n\r\n");
				while (!feof($fp)) {
					$response .= fgets ($fp,128);
				}
				fclose ($fp);
			}
			else {
				$response = false;
				$mt_errstr = $errno.' '.$errstr;
			}
  	    }
    }
	if ($response === false) {
		if (MT_ERR) {
			echo $mt_errstr;
		}
		else {
			header("Location: ".$fallback);
  			exit;
		}
	}
	else {
		return $response;
	}
}


function process_content($pagecontent) {
    if ($pagecontent != '') {
  	    list($headers, $body) = explode("\r\n\r\n", $pagecontent, 2);
  	    $headerlines = explode("\r\n", $headers);
  	    foreach ($headerlines as $header) {
          if (preg_match("/^HTTP|Location:|Vary:|Content-Length:|Content-Type:/i", $header)) {
            header($header);
          }
  	    }
  	    echo $body;
    }
}

FinD Privacy Policy

FinD, Inc. (FinD) is committed to respecting your privacy. We have developed this privacy policy to ensure our members and visitors’ information will not be shared with any third party.

Awareness. FinD provides this Privacy Policy to make you aware of our privacy policy, and to inform you of the way your information is used. We also provide you with the opportunity to remove your name from our mailing list, if you desire to do so.

Information collected. Here are the types of giver information that we collect and maintain:

  • Contact information:  name, organization, complete address, phone number, email address
  • Payment information: credit card number and expiration date, and billing information
  • Shipping information: name, organization, complete address
  • Information concerning how you heard about FinD
  • Information you wish to share: questions, comments, suggestions
  • Your request to receive periodic updates; e.g., upon individual request, we will send periodic communications related to specific fundraising appeals, prayer concerns, and newsletters.

How information is used.  FinD uses your information to understand your needs and provide you with better service. Specifically, we use your information to help you complete a transaction, to communicate back to you, and to update you on ministry happenings. Credit card numbers are used only for donation or payment processing and are not retained for other purposes. We use the comments you offer to provide you with the information requested, and we consider carefully each recommendation as to how we might improve communication.

No sharing of personal information.  FinD will not sell, rent, or lease your personal information to other parties. We assure you that the identity of all our members and visitors will be kept confidential. The use of giver information will be limited to the internal purposes of FinD and only to further the ministry activities and purposes of FinD.

Removing your name from our communications.  It is not our desire to send unwanted communications to our givers. Please contact us if you wish to be removed from our communications list.

Contact us.  If you have comments or questions about our giver privacy policy, please send us an email at info@FinDdiscipleship.org or call us at (832) 303-1144.

logo