PHP - Capture All POST Variables
Solution 1
For a PayPal IPN, you should be able to use $postdata = file_get_contents('php://input');
to fetch the raw post data needed for the validation callback.
Solution 2
I've got a simple method that helps me capture all the post data:
$post_vars = "";
if ($_POST) {
$kv = array();
foreach ($_POST as $k => $v) {
if (is_array($v)):
$temp = array();
foreach ($v as $v2) {
$temp[] = $v2;
}
$kv[] = "$k=" . join("|", $temp);
else:
$kv[] = "$k=$v";
endif;
}
$post_vars = join("&", $kv);
}
This allows you to capture all the post data (regardless of its name or value) and then store than in a string, great for inserting into a database, though you might want to url encode it. I've updated it to include support for arrays but you'll have to customise it for your own requirements, it produces output like this:
firstname=Terry&lastname=Kernan&userid=111111&device=999999999&text=Hello&questions=q1|q2|q3&answers=a1|a2|a3&type=manual
Solution 3
Yes.
On your IPN page, you can log all get, post and cookie variables pretty easy.
Try this:
ob_start();
print_r($_REQUEST);
$data = ob_get_contents();
ob_end_clean();
file_put_contents("Path/to/log.file",$data);
Solution 4
Post values are in the $_POST
array.
Get values are in the $_GET
array.
Get, post and cookie values are placed in $_REQUEST
Simply save and/or print the contents of those arrays as needed.
For more detailed info, check out:
http://php.net/manual/en/language.variables.superglobals.php
Solution 5
<?php
$req = 'What i reveive from paypal=====';
foreach ($_POST as $key => $value) // Loop through the key value pairs
{
$req .= "\n\r$key=$value"; // Add the key value pairs to the variable
}
mail('<Your own email address>','Data',$req,'from: <any email address of your own domain>');//mail yourself
?>
saburius
Updated on June 05, 2022Comments
-
saburius almost 2 years
Is there a way in PHP to capture all post and get variables that are sent to a page?
I am testing my PayPal Subscription website in the PayPal Sandbox but every transaction I do triggers the invalid transaction in my code.
So, I would like to capture everything that PayPal sends to my ipn page and see if I can make sense of what is going on. Is this possible?
Thanks!
-
tacone about 13 yearssimpler: file_put_contents( "path/to/log.file", print_r($_REQUEST, true));
-
saburius about 13 yearshow can i capture it into a variable? my app is already sending an email I could just add it to the email body.
-
Byron Whitlock about 13 years@tacone, didn't know about that second parameter to print_r, thanks!
-
Byron Whitlock about 13 years@saburius the output is in the
$data
variable. -
Terry Kernan over 11 yearsthis looks like a simple method, is there a special handler to register to get this to work?
-
Anomie over 11 years@TerryKernan: No, no special handler. But note that it doesn't work for Content-Type: multipart/form-data. See php.net/manual/en/wrappers.php.php for details.
-
Terry Kernan almost 11 yearsAnother useful one I've been using is: serialize($_POST); as it gives the entire object in a string, agaiun great for writing to a file or storing in the db