Jump to content

passing var


toryadams

Recommended Posts

Ok quick run down... I need to pass a variable from one page[form] to another while skipping a page that is in the middle.

 

The middle page is paypal... after they pay, they are being redirected to a thank you for registering with a email also being sent.

But I need their email from the first page[form].

 

so what i need to figure out or help is:

 

1. First page is a form, they enter name, last name, address, email and so on

2. They are redirected to paypal to pay for a service.

3. Are directed back to my site for a email to be sent to them, but I need their email from the first page.

Link to comment
https://forums.phpfreaks.com/topic/246326-passing-var/
Share on other sites

you add the 'custom' field to the paypal button/form:

<input type='hidden' name='custom' value='yourvar' />

Then using their Instant Payment Notification (IPN) script that can be generated for PHP on their website you can get the variable on the other end.

Link to comment
https://forums.phpfreaks.com/topic/246326-passing-var/#findComment-1265011
Share on other sites

if anyone has used ipn on paypal help would be great...

 

Here is the code...

<?php
$connection = mysql_connect('testingblock.db.6607699.hostedresource.com', 'testingblock', 'KN1ght12') or die(mysql_error());
  	mysql_select_db("testingblock", $connection)or die(mysql_error());

$req = 'cmd=_notify-validate';

// go through each of the POSTed vars and add them to the variable
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// In a live application send it back to www.paypal.com
// but during development you will want to uswe the paypal sandbox

// comment out one of the following lines

$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
//$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

// or use port 443 for an SSL connection
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);


if (!$fp) {

//email
$mail_From = "From: [email protected]";
$mail_To = $email;
$mail_Subject = "HTTP ERROR";
$mail_Body = $errstr;//error string from fsockopen

mail($mail_To, $mail_Subject, $mail_Body, $mail_From); 

// $fh = fopen("logipn.txt", 'a');//open file and create if does not exist
// fwrite($fh, "\r\n/////////////////////////////////////////\r\n HTTP ERROR \r\n");//Just for spacing in log file
//
// fwrite($fh, $errstr);//write data
// fclose($fh);//close file

}
else
{
  fputs ($fp, $header . $req);
  while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {



      $item_name = $_POST['item_name'];
      $item_number = $_POST['item_number'];
      $item_colour = $_POST['custom'];  
      $payment_status = $_POST['payment_status'];
      $payment_amount = $_POST['mc_gross'];         //full amount of payment. payment_gross in US
      $payment_currency = $_POST['mc_currency'];
      $txn_id = $_POST['txn_id'];                   //unique transaction id
      $receiver_email = $_POST['receiver_email'];
      $payer_email = $_POST['payer_email'];

      if (($payment_status == 'Completed') &&   //payment_status = Completed
         ($receiver_email == "[email protected]") &&  
         ($payment_currency == "GBP") &&  
         (!txn_id_used_before($txn_id))) { 

         $receiver = "[email protected]";


$random_num = rand(1,10); 

if (isset($random_num)){
$query = sprintf("SELECT email FROM access_codes WHERE id='".$random_num."'", mysql_real_escape_string($email)); 
$result = mysql_query($query);
$row = mysql_fetch_assoc($result); 


while(!empty($row['email'])){

  $random_num = rand(1,10); 
  var_dump($random_num); 
  $query = sprintf("SELECT email FROM access_codes WHERE id='".$random_num."'", mysql_real_escape_string($email)); 
  $result = mysql_query($query); 
  $row = mysql_fetch_assoc($result);

}

    $query2 = sprintf("SELECT codes FROM access_codes WHERE id='".$random_num."'", mysql_real_escape_string($codes));
    $result2 = mysql_query($query2);
    $row2 = mysql_fetch_assoc($result2); 
    echo $row2['codes']; 



    $Name = "The Streetbeat Team"; 
    $email = "[email protected]";  
    $recipient = "$receiver"; 
    $mail_body = "This is your code for the 10 day free trial of the StreetBeat Int $random_num Please save this email and use the code for your trial.";
    $subject = "This is your coupon code for your trail on U-Network"; 
    $header = "From: ". $Name . "<" . $email . ">\r\n";

    ini_set('sendmail_from', '[email protected]');

    mail($recipient, $subject, $mail_body, $header); 

    $sql = "UPDATE `access_codes` SET `email` =  '{$_POST['email']}' WHERE id='".$random_num."'"; 
    mysql_query($sql) or die(mysql_error());
    
    echo 'A email has been sent to the email you provided. Which is'.$recipient.'If this is not correct please contact us, by email at [email protected], with your correct email and the email you provided';  

    

}


            $mail_To = "[email protected]";
            $mail_Subject = "completed status received from paypal";
            $mail_Body = "completed: $item_number  $txn_id";
            mail($mail_To, $mail_Subject, $mail_Body);


      }
      else
      {

// send an email to say that something went wrong
          $mail_To = "[email protected]";
          $mail_Subject = "PayPal IPN status not completed or security check fail";
//
//you can put whatever debug info you want in the email
//
          $mail_Body = "Something wrong. \n\nThe transaction ID number is: $txn_id \n\n Payment status = $payment_status \n\n Payment amount = $payment_amount";
          mail($mail_To, $mail_Subject, $mail_Body);

      }
    }
    else if (strcmp ($res, "INVALID") == 0) {
//
// Paypal didnt like what we sent. If you start getting these after system was working ok in the past, check if Paypal has altered its IPN format
//
      $mail_To = "[email protected]";
      $mail_Subject = "PayPal - Invalid IPN ";
      mail($mail_To, $mail_Subject, $mail_Body);
    }
  } //end of while
fclose ($fp);
}
?>

 

here is the email i am getting

 

We have had an INVALID response.

 

The transaction ID number is:

 

username =

 

and i am using sandbox... so i did something wrong.

Link to comment
https://forums.phpfreaks.com/topic/246326-passing-var/#findComment-1265162
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.