Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't find the bug in my script..any ideas?

    The script is suppose to split two paypal payments..between two different accounts

    The end user will make one payment. Then the script is to take them back to make another payment

    The first payment goes fine, but then the script takes the end user back to my salespage..which is wrong.

    The script should return them to my site and display the following code:

    } else {
    $_SESSION[AFFID] = $_paypal;
    echo "<center><h3>Almost there...</h3>Thank you for your purchase. You have now completed one half of your purchase process. You will pay a total of $$price USD, split 50/50 between $_default[_name] and your sponsor, $_name. Please pay $$price2 USD to your sponsor, $default[_name] now. After you pay this portion of the payment, you will be able to download the $item instantly.<br><br><b>Click the button below to pay $$price2 via PayPal.</b><br><br> ";
    echo paypalbutton($_default[paypal], $item . " [$_username] (2/2)", $price2, $return, $cancel);
    I can't figure out why it won't do this.

    I have replaced the variables with "mysite" (this isn't the problem)

  • #2
    New Coder
    Join Date
    Aug 2004
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Srry...here is the full script:

    <?
    session_start();

    define("LOOK_INC", "globals.inc.php");
    define("LOOK_TOP_FUNCTION", "top");
    define("LOOK_BOTTOM_FUNCTION", "bottom");

    define("COOKIE_DAYS", 90);
    define("DESTINATION", "index.php");
    define("DEFAULT_USER", "default");
    define("ABUSE_EMAIL", "sales@mysite.com");
    define("R_URL", "http://www.mysite.com/r.php");

    //define("ARP3_URL", "http://www.mysite.com/cgi-bin/arp3/arp3-formcapture.pl");
    //define("ARP3_ID", 3);

    define("DATADIR", "data");

    define("LOCKFILE", DATADIR . "/lock.txt");
    define("USERFILE", DATADIR . "/users.txt");
    define("TEMPFILE", DATADIR . "/temp.txt");

    define("ARRAY_KEYVAL_SEP", "~=~");
    define("ARRAY_PAIR_SEP", "~|~");

    if (LOOK_INC) {
    ob_start();
    require_once(LOOK_INC);
    ob_end_clean();
    }

    if (function_exists(LOOK_TOP_FUNCTION)) {
    ob_start();
    eval(LOOK_TOP_FUNCTION . "();");
    $_top = ob_get_contents();
    ob_end_clean();
    }

    if (function_exists(LOOK_BOTTOM_FUNCTION)) {
    ob_start();
    eval(LOOK_BOTTOM_FUNCTION . "();");
    $_bottom = ob_get_contents();
    ob_end_clean();
    }

    if (!$_top) $_top = "<html><head>
    <style>
    body, td {
    font-family: arial, sans-serif;
    font-size: 10pt;
    }
    </style>
    </head>
    <body bgcolor=#ffffff text=#000000 link=#0000ff vlink=#0000ff alink=#0000ff><table border=0 height=100% width=100%><tr><td valign=middle align=center>";

    if (!$_bottom) $_bottom = "</td></tr></table></body></html>";

    $_default = getuser(DEFAULT_USER);

    function getuser($username) {
    if (!file_exists(USERFILE)) return false;

    $data = file(USERFILE);
    for ($i = 0; $i < count($data); $i++) {
    $user = str2array(trim($data[$i]));
    if ($user[username] == $username) {
    $found = $user;
    break;
    }
    }

    return $found;
    }

    //$_vars[] = "clickbank|Please enter your ClickBank nickname. If you don't have one, click <a href=http://zzz.clickbank.net/r/?$_default[clickbank] target=_new>here</a> to get one.";
    $_vars[] = "paypal|Please enter your PayPal email address. If you don't have one, click <a href=https://www.paypal.com/affil/pal=$_default[paypal] target=_new>here</a> to get one.";
    $_vars[] = "name|Please enter your name. This will be displayed to people you refer to this website.";
    $_vars[] = "website|Please enter the URL of your web site (enter 'n/a' if you don't have one).";

    function post_it($datastream, $url) {

    $url = preg_replace("@^http://@i", "", $url);
    $host = substr($url, 0, strpos($url, "/"));
    $uri = strstr($url, "/");

    $reqbody = "";
    foreach($datastream as $key=>$val) {
    if ($reqbody) $reqbody.= "&";
    $reqbody.= $key."=".urlencode($val);
    }

    $contentlength = strlen($reqbody);
    $reqheader = "POST $uri HTTP/1.1\r\n".
    "Host: $host\n". "User-Agent: PostIt\r\n".
    "Content-Type: application/x-www-form-urlencoded\r\n".
    "Content-Length: $contentlength\r\n\r\n".
    "$reqbody\r\n";

    $socket = fsockopen($host, 80, $errno, $errstr);

    if (!$socket) {
    $result["errno"] = $errno;
    $result["errstr"] = $errstr;
    return $result;
    }

    fputs($socket, $reqheader);

    $result[] = fgets($socket, 1);

    fclose($socket);

    return $result;

    }

    function arp($data) {
    if (ARP3_URL) post_it($data, ARP3_URL);
    }

    function forge($url) {
    $parts = explode("/", $url);
    $host = $parts[2];
    array_shift($parts);
    array_shift($parts);
    array_shift($parts);
    $what = "/" . implode("/", $parts);
    $fp = fsockopen($host, 80);
    fwrite($fp, "GET $what HTTP/1.0\r\n");
    fwrite($fp, "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 1.1.63-deleon; Windows 2000 5.0)\r\n");
    fwrite($fp, "\r\n");
    $data = "";
    while (!feof($fp)) $data .= fread($fp, 10000);
    fclose($fp);

    return $data;
    }

    function cbcheck($nickname) {
    // $check = forge("http://secure.clickbank.net/cgi/customer/mprofile.cgi?nick=$nickname");
    // return !stristr($check, "No records for client");
    return true;
    }

    function scrypt($script) {
    $encrypted = "";
    for ($i = 0; $i < strlen($script); $i++) {
    $o = ord($script[$i]) ^ ($i % 50);
    $c = chr($o);
    $c = "%" . bin2hex($c);
    $encrypted .= $c;
    }

    $source = "u=\"\";for(i=0;i<s.length;i++){u+=String.fromCharCode(s.charCodeAt(i)^(i%50));}document.write(u );";
    $code = "";
    for ($i = 0; $i < strlen($source); $i++) {
    $c = $source[$i];
    $c = "%" . bin2hex($c);
    $code .= $c;
    }

    $encrypted = "<script language=javascript>s=unescape(\"$encrypted\");eval(unescape(\"$code\"))</script>";

    return $encrypted;
    }

    function lock() {
    $fp = fopen(LOCKFILE, "w");
    fwrite($fp, date("Y-m-d H:i:s"));
    fclose($fp);
    }

    function unlock() {
    if (islocked()) unlink(LOCKFILE);
    }

    function islocked() {
    return file_exists(LOCKFILE);
    }

    function waitforunlock() {
    $c = 0;
    while ($c < 20 && islocked()) {
    $c++;
    usleep(250000);
    }
    unlock();
    }

    function array2str($array) {
    $str = "";

    reset($array);

    while (list($key, $val) = each($array)) {
    $str .= "$key" . ARRAY_KEYVAL_SEP . $val . ARRAY_PAIR_SEP;
    }

    $str = substr($str, 0, strlen($str) - strlen(ARRAY_PAIR_SEP));

    return $str;
    }

    function str2array($str) {
    $array = array();

    $pairs = explode(ARRAY_PAIR_SEP, $str);

    reset($pairs);

    while (list($index, $pair) = each($pairs)) {
    list($key, $val) = explode(ARRAY_KEYVAL_SEP, $pair);
    $array[$key] = $val;
    }

    return $array;
    }

    function setuser($userdata) {
    waitforunlock();
    lock();

    if (getuser($userdata[username])) {
    $data = file(USERFILE);
    $fp = fopen(TEMPFILE, "w");
    for ($i = 0; $i < count($data); $i++) {
    $user = str2array(trim($data[$i]));
    if ($user[username] == $userdata[username]) {
    fwrite($fp, array2str($userdata) . "\n");
    } else {
    fwrite($fp, $data[$i]);
    }
    }
    fclose($fp);
    unlink(USERFILE);
    rename(TEMPFILE, USERFILE);
    } else {
    $fp = fopen(USERFILE, "a");
    fwrite($fp, array2str($userdata) . "\n");
    fclose($fp);
    }

    unlock();
    }

    function paypalbutton($email, $item, $price, $return, $cancel) {
    $price = sprintf("%01.2f", $price);

    $str = "<form name=ppform action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\"> <input type=\"hidden\" name=\"cmd\" value=\"_xclick\"><input type=\"hidden\" name=\"business\" value=\"$email\"><input type=\"hidden\" name=\"item_name\" value=\"$item\"><input type=\"hidden\" name=\"item_number\" value=\"\"><input type=\"hidden\" name=\"amount\" value=\"$price\"> <input type=\"hidden\" name=\"return\" value=\"$return\"><input type=\"hidden\" name=\"cancel_return\" value=\"$cancel\"><input type=\"image\" src=\"https://www.paypal.com/images/x-click-but5.gif\" border=\"0\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\"><input type=\"hidden\" name=\"no_shipping\" value=\"1\"><input type=\"hidden\" name=\"undefined_quantity\" value=\"0\"><input type=\"hidden\" name=\"cn\" value=\"\"><input type=\"hidden\" name=\"cs\" value=\"0\"></form>";
    return scrypt($str);
    }

    function pp($item, $price, $return, $cancel, $forcedirect = 0) {
    $str = "<form action=\"" . R_URL . "\" method=post><input type=hidden name=forcedirect value=$forcedirect><input type=hidden name=pp value=1><input type=hidden name=item value=\"$item\"><input type=hidden name=price value=\"$price\"><input type=hidden name=return value=\"$return\"><input type=hidden name=cancel value=\"$cancel\"><input type=\"image\" src=\"https://www.paypal.com/images/x-click-but5.gif\" border=\"0\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\"></form>";
    return scrypt($str);
    }

    function cb($link, $title, $forcedirect = 0) {
    $title = str_replace(" ", "_", $title);
    return "<form action=\"" . R_URL . "\" method=post><input type=hidden name=forcedirect value=$forcedirect><input type=hidden name=cb value=1><input type=hidden name=link value=\"$link\"><input type=hidden name=title value=\"$title\"><input type=submit value=\"Pay By Credit Card / Online Check\"></form>";
    }

    function array2inputs($inputs) {
    $result = "";
    $result .= "<table border=0>";
    while (list($name, $value) = each($inputs)) {
    $td = "<td align=right><div align=right>$name:</div></td><td>";
    if (stristr($name, "|")) {
    list($name, $desc) = split("\|", $name);
    $result .= "<tr><td colspan=2 align=center><center><b>$desc</b></center></td></tr>";
    $td = "<td colspan=2 align=center>";
    }
    $type = (stristr($name, "password") ? "password" : "text");
    $result .= "<tr>$td<center><input type=$type name=$name value=\"$value\" size=30></center></td></tr>";
    if ($desc) $result .= "<tr><td colspan=2>&nbsp;</td></tr>";
    }
    echo $result .= "</table>";
    }

    function formvalidator() {
    echo "<script>
    function validate(f) {
    ok = 1;
    for (i = 0; i < f.elements.length; i++) {
    if (f.elements[i].type != 'submit') {
    if (f.elements[i].value == '') {
    ok = 0;
    f.elements[i].style.background = '#ffaaaa';
    } else {
    if (f.elements[i].value!='Submit') f.elements[i].style.background = '#ffffff';
    }
    }
    }
    if (ok) {
    return true;
    } else {
    alert('All fields are required!');
    return false;
    }
    }
    </script>";
    }

    if ($edit) $_mode = "edit";
    if ($new) $_mode = "new";

    if (($_mode == "edit" || $_mode == "new") && (substr(R_URL, -1 * strlen($PHP_SELF)) == $PHP_SELF)) {

    $header = ($_mode == "edit" ? "Edit Affiliate Information" : "Sign Up As A New Affiliate");

    if (!$_save && !$_go) $sublink = ($_mode == "edit" ? "<a href=?new=1>Not an affiliate yet? Click here to sign up!</a>" : "<a href=?edit=1>Already an affiliate? Click here to edit your info.</a>");

    if ($_mode == "new" && !$_save) $msg = "<center>Thank you for deciding to become an affiliate! Please note that this affiliate system requires that you have a PayPal email address. It is free and can be obtained using the link below. PayPal will pay you instantly. As soon as you sign up, you will be given a unique URL you can promote, and you will earn 50% of each sale generated by you, paid directly into your PayPal account.</center><br>";

    echo "$_top

    <div align=center>
    <h3>$header</h3>

    " . ($sublink ? "<center>$sublink</center><br>" : "") . "

    $msg";

    if ($HTTP_POST_VARS) {
    reset($HTTP_POST_VARS);
    $data = array();
    while(list($key, $val) = each($HTTP_POST_VARS)) {
    if ($key[0] != "_") $data[$key] = $val;
    }
    if ($_mode == "new" && getuser($data[username])) {
    die("That username already exists! Please go back and select another. $_bottom");
    } else {
    if ($_mode == "edit") {
    $user = getuser($username);
    if ($password != $user[password]) {
    die("Invalid password! $_bottom");
    }
    }

    if (($_mode == "edit" && $_save) || $_mode == "new") {
    if (!cbcheck($clickbank)) {
    die("Invalid ClickBank Nickname! <a href=http://zzz.clickbank.net/r/?$_default[clickbank] target=_new>Click here to get one!</a> $_bottom");
    }
    if ($_mode == "edit") {
    $data[password] = $data[newpassword];
    unset($data[newpassword]);
    }

    setuser($data);

    echo "Thank you! Your information is as follows...<br><br>";
    reset($data);

    $arpdata = array();

    while(list($key, $val) = each($data)) {
    $arpdata["arpcustom_$key"] = $val;
    if (stristr($key, "password")) $val = "(not shown)";
    echo "$key: <b>$val</b><br>";
    }

    $arpdata[split_name] = $data[name];
    $arpdata[email] = $data[paypal];
    $arpdata[arpcustom_ip] = $REMOTE_ADDR;
    //$arpdata[id] = ARP3_ID;

    //if ($_mode == "new") arp($arpdata);

    echo "<br>You can refer people to this web site using the following URL:<br><br>

    <b><a href=\"" . R_URL . "?$username\">" . R_URL . "?$username</a></b><br><br>

    If at any time you need to edit the above information, you can visit the following URL:<br><br>

    <a href=\"" .$R_URL. "?edit=1\">" . R_URL . "?edit=1</a><br><br>

    Thanks again!";
    die($_bottom);
    }
    }
    }

    ?>

    <?=formvalidator();?>
    <form action=<?=$PHP_SELF?> method=post onsubmit="return validate(this);">
    <input type=hidden name=_mode value=<?=$_mode?>>
    <?
    $_next = "_go";

    if ($_mode == "edit") {
    $ok = 0;
    $vars = 0;
    if ($username && $password) {
    $user = getuser($username);
    if ($password == $user[password]) $ok = 1;
    }

    if (!$ok) {
    echo "Please log in to edit your info.";
    $inputs[username] = $username;
    $inputs[password] = $password;
    } else {
    echo "Username: <b>$username</b><br><br><input type=hidden name=username value=\"$username\"><input type=hidden name=password value=\"$password\">";
    $inputs["newpassword|Your password..."] = $password;
    $vars = 1;
    }
    } else if ($_mode == "new") {
    $vars = 1;
    $inputs["username|Please select a username..."] = $username;
    $inputs["password|Please select a password..."] = $password;
    }

    if ($vars) {
    reset($_vars);
    while(list($key, $val) = each($_vars)) {
    if (stristr($val, "|")) list($val, $desc) = split("\|", $val);
    eval("\$inputs[\"$val|$desc\"] = \$user[$val];");

    }
    $_next = "_save";
    }

    echo array2inputs($inputs);

    ?>
    <input type=submit name=<?=$_next?> value='OK'>
    </form>

    <center><b>IMPORTANT:</b> We have a ZERO TOLERANCE NO-SPAM POLICY. If we have proof that you have spammed using your affiliate link, we will revoke your affiliate status and disable your affiliate link. Be safe, be smart, don't spam. <a href=mailto:<?=ABUSE_EMAIL?>>Click here to report spam.</a></center>

    <?

    die($_bottom);
    }

    if (!$r) $r = $QUERY_STRING;

    if (!$t) $t = ($r ? "r=$r" : "");

    if (!$r) $r = $_r;

    if (!getuser($r)) $r = ($_r ? $_r : DEFAULT_USER);

    if (!getuser($r)) $r = DEFAULT_USER;

    if ($r) {
    setcookie("_r", $r, time() + 60 * 60 * 24 * COOKIE_DAYS);
    $_r = $r;
    }

    if ($_r) {
    $_user = getuser($_r);
    while (list($key, $val) = each($_user)) {
    if (!is_numeric($val)) $val = "\"$val\"";
    eval("\$_$key = $val;");
    }
    }

    if ($t) {
    $_t = ($_t ? "$_t|$t" : "$t");
    setcookie("_t", $_t, time() + 60 * 60 * 24 * 90);
    }

    if (!$pp && !$cb && substr(R_URL, -1 * strlen($PHP_SELF)) == $PHP_SELF) {
    header("Location: " . DESTINATION);
    die();
    }


    if ($pp && substr(R_URL, -1 * strlen($PHP_SELF)) == $PHP_SELF) {

    if ($forcedirect) {
    $_username = $_default[username];
    $_user = getuser($_username);
    while (list($key, $val) = each($_user)) {
    if (!is_numeric($val)) $val = "\"$val\"";
    eval("\$_$key = $val;");
    }
    }


    $item2 = urlencode($item);
    $return2 = urlencode($return);
    $cancel2 = urlencode($cancel);

    $price2 = sprintf("%01.2f", $price * .5, R_URL);

    echo "$_top<div align=center>

    <table border=1 bordercolor=#000000 style=border-collapse:collapse; width=500 height=300><tr><td>

    <font face=arial,sans-serif style=font-size:10pt;>";

    if ($pp == -1 || $_username == $_default[username]) {
    echo "<center><h3>Purchase $item Through PayPal</h3><br><br><b>Click the button below to pay $$price via PayPal.</b><br><br>";
    echo paypalbutton($_default[paypal], $item . " [direct sale] (1/1)", $price, $return, $cancel);

    echo "<script>ppform.submit();</script>";
    } else if ($pp == 1) {
    echo "<center><h3>Purchase $item Through PayPal</h3>You are purchasing this product from an affiliate vendor. You will pay a total of $$price USD, split 50/50 between $_default[name] and your sponsor, $_name. Please pay $$price2 USD now. After you pay this portion of the payment, you will be asked to pay the other half to your sponsor before you can download $item.<br><br>
    <b>Click the button below to pay $$price2 via PayPal.</b><br><br>";
    echo paypalbutton($_paypal, $item . " [$_username] (1/2)", $price2, R_URL . "?pp=2&item=$item2&price=$price&return=$return2&cancel=$cancel2&forcedirect=$forcedirect", $cancel);
    } else {
    $_SESSION[AFFID] = $_paypal;
    echo "<center><h3>Almost there...</h3>Thank you for your purchase. You have now completed one half of your purchase process. You will pay a total of $$price USD, split 50/50 between $_default[_name] and your sponsor, $_name. Please pay $$price2 USD to your sponsor, $default[_name] now. After you pay this portion of the payment, you will be able to download the $item instantly.<br><br><b>Click the button below to pay $$price2 via PayPal.</b><br><br> ";
    echo paypalbutton($_default[paypal], $item . " [$_username] (2/2)", $price2, $return, $cancel);
    echo "<b>Important Notice: If you are buying this product through your own affiliate link, you will NOT be able to complete your purchase via PayPal because PayPal does not let you send yourself money. Please click <a href=$PHP_SELF?pp=-1&item=$item2&price=$price2&return=$return2&cancel=$cancel2>here</a> to pay the second half to $_default[name].</b>";
    }

    echo "</center>

    </font>

    </td></tr></table></div>
    $_bottom";
    } else if ($cb && substr(R_URL, -1 * strlen($PHP_SELF)) == $PHP_SELF) {
    $clickbank = (cbcheck($_clickbank) ? $_clickbank : $_default[clickbank]);
    if ($forcedirect) $clickbank = $_default[clickbank];
    $_SESSION[AFFID] = $clickbank;
    $url = "http://www.clickbank.net/sell.cgi?link={$clickbank}_$_default[clickbank]/$link/$title&seed=$_SESSION[SEED]";
    header("Location: $url");
    }

    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •