Dionysus
asked on
PHP and PayPal's returned $_POST variables - how to match variables to strings?
I am testing a system and I am at the point where I've made the (test) purchase and PayPal has sent me back to my return page with a long string of variables in the following format :
cmd=_notify-validate&payme nt_date=18 %3A20%3A11 +Mar+21%2C +2006+PST& txn_type=w eb_accept& last_name= Buyer&resi dence_coun try=CA&ite m_name=Mer chant&paym ent_gross= &mc_curren cy=CAD&bus iness=sale s%40mercha nt.com&pay ment_type= instant&ve rify_sign= An5ns1Kso7 MWUdW4ErQK JJJ4qi4-Ah FhwMdtcrBW QYPu7jYen. 7IBSuN&pay er_status= unverified &test_ipn= 1&tax=0.00 &payer_ema il=test%40 customer.c om&txn_id= 7WT0194565 41558329&q uantity=1& receiver_e mail=someo ne%40merch ant.com&fi rst_name=D ion&payer_ id=F34564R FQ5WQ&rece iver_id=R4 T13RSEJ5NA &item_numb er=1&payme nt_status= Completed& payment_fe e=&mc_fee= 1.79&shipp ing=0.00&m c_gross=42 .75&custom =&charset= windows-12 52¬ify_ version=2. 1
Now I've taken this and assigned it to a variable:
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($va lue));
$req .= "&$key=$value";
So far so good... now I tried to split the string so I could get 2 key/value pairs isolated. I want the payer_email and the payment_status separated from the rest, so I started with the following:
$postarray = explode("&", $req);
Now the problem is, how do I split it again and do a test for $postarray['payment_status ']?
I can try and isolate the pairs using $postarray[14] but I'd like to specify by name in case the order of variables changes at some point in the future...
Can anyone help?
Thanks,
Dion
cmd=_notify-validate&payme
Now I've taken this and assigned it to a variable:
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($va
$req .= "&$key=$value";
So far so good... now I tried to split the string so I could get 2 key/value pairs isolated. I want the payer_email and the payment_status separated from the rest, so I started with the following:
$postarray = explode("&", $req);
Now the problem is, how do I split it again and do a test for $postarray['payment_status
I can try and isolate the pairs using $postarray[14] but I'd like to specify by name in case the order of variables changes at some point in the future...
Can anyone help?
Thanks,
Dion
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks man.. the only thing is that you had missed a closing bracket.. but apart from that.. you did exactly what I wanted.
Take care!
-Dion
Take care!
-Dion
ASKER
I received a POST from PayPal, and using that code, created that long string. Now I need to know how to break it down further as I said previously.
Thanks!