I have a paypal form that submits a the value of a custom hidden input. Since I have a few extra pieces of data to parse, I've added them as a query string. i.e.
<input type="hidden" name="custom" value="payment-type=deposit&user-id=<?php echo $user_id; ?>&user-name=<?php echo $user_name; ?>">
This outputs as:
<input type="hidden" name="custom" value="payment-type=deposit&user-id=1&user-name=admin">
I then have a file called paypal-ipn.php which communicates with paypal and also adds the payment data to my database. I get the values of each of the inputs using the $_POST method, i.e
$item_name = $_POST['item_name']; // wedding name
$booking_id = $_POST['item_number']; // booking id
$payment_status = $_POST['payment_status']; // payment status
$payment_amount = $_POST['mc_gross']; // amount?
$payment_currency = $_POST['mc_currency']; // currency
$txn_id = $_POST['txn_id']; // transaction id
$receiver_email = $_POST['receiver_email']; // reciever email i.e. your email
$payer_email = $_POST['payer_email']; // payer email i.e. client email
$custom_variables = $_POST['custom'];
The last one will (hopefully) return my query string. My question is, how can I separate out my query string into separate variables, i.e.
$payment_type = PAYMENT TYPE FROM STRING
$user_id = USER ID FROM STRING
$user_name = USER NAME FROM STRING
Is there a way to do this using php?
Here is my latest code that I'm trying based on answers below:
$custom_variables = $_POST['custom'];
parse_str($custom_variables);
echo $payment_type;
echo $user_id;
echo $user_name;
parse_str($str, $output);
$payment_type = $output['payment_type'];
$user_id = $output['user_id'];
$user_name = $output['user_name'];