Added Tell-A-Friend
v2.2
-> Added version list.
-> Added ability to only allow purchasing customers to be affiliates.
-> Added giveaway product functionality.
-> Added affiliate emailing.
-> Added a few bug fixes.
v2.3
-> Added code for parsing PHP in templates.
-> Updated code that decides who gets OTO sale.
-> Major Security update tracks purchases by IP and only allows
Completed payments to be redirected to the download page.
-> Added ability to only allow OTO customers to get commissions on the OTO.
-> Added ability to disable download emails from automatically being sent.
-> Added support for all PayPal currencies.
-> BUG FIX: Corrected 48 hour extension of download link to add 48 hours to THIS moment.
-> Added script configure util (config.php)
v2.4
-> BUG FIX: When OTO commission is set to zero, affiliate always gets the commission.
-> BUG FIX: Affiliate cookie now cleared if only customers are allowed to be affiliates.
-> BUG FIX: Removed case-sensitive referrer domain comparison for TAF.
-> IPN script now prevents people from paying less than stated price for products.
-> IPN script now prevents people from purchasing using different emails from the same domains.
-> Added admin section for viewing fraudulent transactions.
-> Added version number to ipn.php, config.php and settings.php
-> Added back-end search features for sales records.
-> Added download security.
*/
$sys_version = 2.4;
include("settings.php");
function searchKeywords($url){
$parts = parse_url($url);
$host = str_replace("www.", "", $parts["host"]);
$keywords = "";
parse_str($parts["query"], $vars);
if(strpos(" $host", "google")){
$keywords = urldecode($vars["q"]);
}
elseif(strpos(" $host", "yahoo")){
$keywords = urldecode($vars["p"]);
}
elseif(strpos(" $host", "live")){
$keywords = urldecode($vars["q"]);
}
elseif($vars["keywords"]){
$keywords = urldecode($vars["keywords"]);
}
elseif($vars["query"]){
$keywords = urldecode($vars["query"]);
}
else{
$keywords = urldecode($vars["q"]);
}
return $keywords;
}
function evalPHP($template){
# Make all settings.php variables accessible to template PHP code.
global $sys_admin_username, $sys_admin_password, $sys_domain, $sys_support_address,
$sys_script_folder, $sys_template_folder, $sys_default_email, $sys_item_name,
$sys_item_number, $sys_item_cost, $sys_oto, $sys_oto_name, $sys_oto_number,
$sys_oto_cost, $sys_oto_percent, $sys_item_cancel_url, $sys_expire_hours,
$sys_blocked, $sys_secure_dl, $sys_tell_subject, $sys_tell_body,
$sys_purchasers_only, $sys_purchasers_override, $sys_giveaway_product,
$sys_oto_purchasers_only, $sys_oto_purchasers_override;
# Eval all php code in a template and plug result into output.
$output = "";
$last = 0;
$i = strpos($template, "", $i);
$phpcode = trim(str_replace(array(""), "", substr($template, $i, $i2 - $i)));
$val = eval($phpcode);
$output .= $val;
$last = $i2 + 3;
$i = strpos($template, "", $i);
$phpcode = trim(str_replace(array("=", "?>"), "", substr($output, $i, $i2 - $i)));
$val = eval("return $phpcode;");
$output2 .= $val;
$last = $i2 + 3;
$i = strpos($output, "=", $i2);
}
$output2 .= substr($output, $last, strlen($output) - $last);
return $output2;
}
function showTemplate($filename){
include($filename);
return;
$output = "";
$fh = @fopen($filename, "r");
while($s = fgets($fh)){
$output .= $s;
}
@fclose($fh);
echo evalPHP($output);
}
function getIPSalesRecord($oto = false){
global $sys_template_folder, $sys_oto_number;
$ip = $_SERVER["REMOTE_ADDR"];
$sales = @file($sys_template_folder . "ipn.txt");
$output = "";
foreach($sales as $sale){
$sale = explode("|", str_replace(array("\r", "\n"), "", $sale));
if($sale[14]==$ip){
$valid = true;
if($oto && $sale[2]!=$sys_oto_number){
$output = "";
$valid = false;
}
if($valid){
$output = $sale;
break;
}
}
}
return $output;
}
function getOTOSalesRecord($affemail){
global $sys_template_folder, $sys_oto_number;
$sales = @file($sys_template_folder . "ipn.txt");
$output = "";
foreach($sales as $sale){
$sale = explode("|", str_replace(array("\r", "\n"), "", $sale));
if($sale[4]==$affemail){
$valid = true;
if($sale[2]!=$sys_oto_number){
$output = "";
$valid = false;
}
if($valid){
$output = $sale;
break;
}
}
}
return $output;
}
function sys_download_url($oto){
$md5 = uniqid("");
return "index.php?action=dlid&oto=$oto&pid=$md5";
}
$action = $_REQUEST["action"];
if(substr($action, 0, 5)=="admin" && $action != "admin" && $action != "adminlogin" && !$_COOKIE["admin"]){
# Not logged in. Redirect to login.
header("Location: $_SERVER[PHP_SELF]?action=admin");
exit;
}
# Redirectin case PayPal goofs and fails to do so.
if(isset($_COOKIE["first"]) && !isset($_COOKIE["giveaway"]) && ($action == "squeeze"| $action == "downloadoto" | ($action=="" && $_SERVER["QUERY_STRING"] != "")) && !isset($_GET["e"])){
# Check for customer IP address in IPN file.
if(isset($_COOKIE["oto"])){
$oto = true;
}
else{
$oto = false;
}
$sale = getIPSalesRecord($oto);
if(is_array($sale)){
# Purchase record found.
if(isset($_COOKIE["oto"])){
setcookie("otodl", time(), time()+(3600*$sys_expire_hours), "/", "." . $sys_domain);
$url = "index.php?action=downloadoto";
}
elseif(isset($_COOKIE["ordered"])){
$url = "index.php?action=squeeze";
}
else{
# ??? - No purchase or OTO cookie found. Assume non OTO purchase.
$url = "index.php?action=squeeze";
}
# Clear first cookie.
setcookie("first", 0, time()-3600, "/", "." . $sys_domain);
# Send to appropriate page.
echo "
";
}
elseif($_GET["tries"]<11){
# Give one minute for PayPal to post IPN record before giving up and showing an error.
if(!isset($_GET["tries"])){
$tries = 1;
}
else{
$tries = $_GET["tries"] + 1;
}
$seconds = 60 - ($tries * 5);
echo "
Waiting for PayPal confirmation of purchase, please wait...
$seconds seconds left...
(This page will refresh every 5 seconds until PayPal provides confirmation.)
";
}
else{
# IP not found in records. Show error message.
if(substr($sys_support_address, 0, 7)=="http://"){
$eaddress = $sys_support_address;
}
else{
$eaddress = "mailto:$sys_support_address";
}
echo "
Purchase record not found.
We apologize for the inconvenience, but there was a problem confirming your purchase. Please contact our technical
support staff for your download link at:
";
foreach($affs as $aff){
# Send the mailer.
$sendbody = str_replace("[EMAIL]", $aff, $ebody);
@mail($aff, $esubject, $sendbody, $headers);
echo "
$aff .. ";
flush();
}
echo "
$adminfooter
Back to Menu
";
exit;
}
elseif($action=="adminfraud"){
# Show all fraudulent transactions.
$records = @file($sys_template_folder . "fraud.txt");
if($records){
$rcount = count($records);
}
else{
$rcount = 0;
$records = array();
}
echo "
$adminheader
Back to Menu
$rcount total fraudulent transactions. Fraudulent buyers do not receive the download.
It is recommended that you report fraudulent buyers to PayPal at 888-215-5506.
$adminfooter";
exit;
}
elseif($action=="adminapprove"){
# Add record into ipn.txt, since it wasn't actually fraud.
$records = @file($sys_template_folder . "fraud.txt");
foreach($records as $record){
$rec = explode("|", $record);
if($rec[0]==$_REQUEST["id"]){
# Add this record to ipn.txt file.
$fh = fopen($sys_template_folder . "ipn.txt", "a+");
fwrite($fh, $record);
fclose($fh);
if(substr($sys_support_address, 0, 7)=="http://"){
$eaddress = "noreply@$sys_domain";
$support = "For support, visit our web site at:\n\n$sys_support_address";
}
else{
$eaddress = $sys_support_address;
$support = "Reply to this email with any questions or support needs you may have.";
}
$subject = "Your download link.";
$expires = time() + (3600 * $sys_expire_hours);
$time = time();
$body = "$rec[5],\n\nThank you for your purchase.\nTo download your copy, click here:\n\nhttp://$sys_domain" . $sys_script_folder . "?action=download&id=$rec[0]\n\nYou have $sys_expire_hours hours to download before the link expires.\nWe appreciate your business.\n$support\n\nThanks again.\n";
# Send download notification to purchaser.
@mail($rec[4], $subject, $body, "From: $sys_item_name <$eaddress>\r\nReply-To: $eaddress\r\nX-Mailer: PHP" . phpversion());
}
}
echo "$adminheader
Back to Menu
The customer has been emailed their download link.
";
exit;
}
elseif($action=="adminlogout"){
# Logout.
setcookie("admin", "", time() - 3600);
header("Location: $_SERVER[PHP_SELF]");
exit;
}
}
# If we made it here, this needs to be cleared.
setcookie("first", 0, time()-3600, "/", "." . $sys_domain);
if($filename){
# Show appropriate page.
showTemplate($filename);
}
else{
# Odd.
echo "
There was a problem processing your request. Please send the following information in a ticket to AskJonLeger.com: