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 "
|
|
|
|
|
You will no longer receive email from $sys_item_name.
"; exit; } } elseif($action=="downloadfile"){ # } # All other actions require that user has ordered and # cookie is set. If it's not, then it's expired. elseif(isset($_COOKIE["ordered"])){ # Kill "first" cookie if($action=="oto"){ # Show oto page. $filename = $sys_template_folder . "oto.html"; } elseif($action=="squeeze"){ $sale = getIPSalesRecord(); if(is_array($sale)|isset($_COOKIE["giveaway"])){ # Show name squeeze page. $filename = $sys_template_folder . "squeeze.html"; } else{ # Not safe, show expired. $filename = $sys_template_folder . "downloadexpired.html"; } } elseif($action=="download"){ $sale = getIPSalesRecord(); if(is_array($sale)|isset($_COOKIE["giveaway"])){ if($sys_oto && !isset($_GET["dl"])){ # Show OTO page. $filename = $sys_template_folder . "oto.html"; } else{ # Show download page. $filename = $sys_template_folder . "download.html"; } } else{ # Not safe, show expired. $filename = $sys_template_folder . "downloadexpired.html"; } } elseif($action=="downloadoto" && isset($_COOKIE["oto"])){ $sale = getIPSalesRecord(true); if(is_array($sale)){ # Show OTO download page. $filename = $sys_template_folder . "downloadoto.html"; } else{ # Invalid IP. $filename = $sys_template_folder . "downloadexpired.html"; } } elseif($action=="downloadoto"){ # Show expired since visitor doesn't have oto cookie. $filename = $sys_template_folder . "downloadexpired.html"; } else{ # Expired. $filename = $sys_template_folder . "downloadexpired.html"; } } elseif($action=="order" && !isset($_COOKIE["cookietest"])){ # No cookies. Show error. $filename = $sys_template_folder . "nocookies.html"; } elseif($action){ # Cookie's gone. Download has expired. $filename = $sys_template_folder . "downloadexpired.html"; } if($action=="admin"){ # Get username/password for admin area. echo " "; exit; } elseif($action=="adminlogin"){ # Verify admin username/password. if($_POST["username"] == $sys_admin_username && $_POST["password"] == $sys_admin_password){ # Valid. Cookie and redirect. setcookie("admin", true); header("Location: $_SERVER[PHP_SELF]?action=adminmenu"); exit; } else{ echo "Invalid username or password."; exit; } } if($_COOKIE["admin"]){ $adminheader = "
$7 Secrets Scripts v$sys_version
"; $adminfooter = "Admin Panel
$taf people have been emailed using the tell-a-friend script.
$adminfooter "; exit; } elseif($action=="adminbuys"|$action=="adminmine"){ # Show all customers. $records = @file($sys_template_folder . "ipn.txt"); $count = 0; $count = $_REQUEST["count"]; if($records){ $rcount = count($records); } else{ $rcount = 0; $records = array(); } if($count){ $showing = "last $count"; } else{ $showing = "all $rcount"; } if($action=="adminmine"){ $showing = "only sales paid to you"; } echo " $adminheader Back to MenuClicking the EXPIRES link will add another $sys_expire_hours hours to the customer's download link expiration.
$rcount total records. Showing $showing. Your sales are highlighted.
| PayPal Receipt ID | Item Number | Affiliate Email | Customer Email | First Name | Last Name | Payment | Bought | Expires |
| $record[0] | $record[2] | $record[3] | $record[4] | $record[5] | $record[6] | $record[8] | $date | $expires |
$rcount total records. Showing $showing. Your sales are highlighted.
| Referrer | Domain | Keywords | Sales |
| $sref | $host | $keywords | $sales |
$rcount total records. Showing $showing. Your sales are highlighted.
| Domain | Sales |
| $ref | $sales |
$rcount total records. Showing $showing. Your sales are highlighted.
| Affiliate | Sales |
| $ref | $sales |
Link expiration has been extended by $sys_expire_hours hours.
Give customer this link to download:
http://$sys_domain" . $sys_script_folder . "?action=download&id=$id
$adminfooter "; } else{ echo " Back to MenuNo matching purchase record found.
"; } exit; } elseif($action=="adminemailaffiliates"){ # Show affiliate mailer form. echo " $adminheader Back to Menu $adminfooter "; exit; } elseif($action=="adminemailaffiliates2"){ # Send a mailer to all affiliates who aren't unsubed. # -- First read unsub file. $unsubs = @file($sys_template_folder . "unsubs.txt"); if(!is_array($unsubs)){ # No unsubs. $removed = array(); } else{ $removed = array(); foreach($unsubs as $aff){ $aff = str_replace(array("\r", "\n"), "", $aff); $removed[$aff] = true; } } # Read IPN file and get unique affiliates. $affiliates = array(); $sales = @file($sys_template_folder . "ipn.txt"); foreach($sales as $sale){ $sale = explode("|", $sale); if(!isset($affiliates[$sale[3]])){ $affiliates[$sale[3]] = 1; } else{ $affiliates[$sale[3]]++; } } if(substr($sys_support_address, 0, 7)=="http://"){ $eaddress = "noreply@$sys_domain"; } else{ $eaddress = $sys_support_address; } $headers = "From: $sys_item_name<$eaddress> X-Sender: $sys_item_name<$eaddress> X-Mailer: PHP " . phpversion() . " X-Priority: 3 Return-Path: $sys_item_name<$eaddress> Reply-To: $sys_item_name<$eaddress>"; $affs = array(); $esubject = $_POST["esubject"]; $ebody = stripslashes($_POST["ebody"]); $ebody .= "\n===\nTo stop receiving emails from $sys_item_name, click this link:\nhttp://$sys_domain" . $sys_script_folder . "?action=remove&email=[EMAIL]"; foreach($affiliates as $aff => $sales){ if(!$removed[$aff] && $sales >= $_POST["esales"]){ $affs[] = $aff; } } echo " $adminheaderSending " . count($affs) . " emails...
"; foreach($affs as $aff){ # Send the mailer. $sendbody = str_replace("[EMAIL]", $aff, $ebody); @mail($aff, $esubject, $sendbody, $headers); echo "$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.
| PayPal Receipt ID | Item Number | Affiliate Email | Customer Email | First Name | Last Name | Payment | Date | |
| $record[0] | $record[2] | $record[3] | $record[4] | $record[5] | $record[6] | $record[8] | $date | not fraud |
The customer has been emailed their download link.
"; exit; } elseif($action=="adminsearch"){ # Show sales search form. echo " $adminheader $adminfooter "; exit; } elseif($action=="adminsearch2"){ echo "$adminheaderMatching Records:
Clicking the EXPIRES link will add another $sys_expire_hours hours to the customer's download link expiration.
| PayPal Receipt ID | Item Number | Affiliate Email | Customer Email | First Name | Last Name | Payment | Bought | Expires |
| $rec[0] | $rec[2] | $rec[3] | $rec[4] | $rec[5] | $rec[6] | $rec[8] | $date | $expires |
$matches matching record(s) found.
"; 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:
af:$_COOKIE[aff]
ct:$_COOKIE[cookietest]
or:$_COOKIE[ordered]
ot:$_COOKIE[oto]
ac:$action