2

I try to save data from a FORM to file. But when 'submit' to external URL my script doesn't see $_POST array. How to save $_POST which I send not receive.

I can save $_POST data I received (I sent to my script and save as post_array.txt). But I have to send it to external url. I tried to receive and resend saved $_POST using cURL but I cannot do redirect with $_POST. So my customer stays on my page but should be redirected to payment page with $_POST data.

html : <form method="POST" action="cert.php">
php :  cert.php

file_put_contents('post_array.txt', $_POST, FILE_APPEND);
$url = 'https://sandbox.przelewy24.pl/trnDirect';
$fields =['p24_merchant_id' => $_POST['p24_merchant_id'],
        'p24_session_id' => $_POST['p24_session_id'],
        'p24_amount' => $_POST['p24_amount'],
        'p24_currency' => $_POST['p24_currency'],
        'p24_sign' => md5($_POST['p24_session_id'].'|'.$_POST['p24_merchant_id'].'|'.$_POST['p24_amount'].'|'.$_POST['p24_currency'].'|'.$_POST['p24__sign'])];

//open connection
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
// this cURL dosnt have a redirect option coz it doesnt work for me :(

// execute!
$response = curl_exec($ch);
file_put_contents('response.txt', $response, FILE_APPEND);
// close the connection, release resources used
curl_close($ch);

Because cURL doesnt work as expected i want to direct send $_POST do external page. (it works well , but i dont have saved $_POST in my file) How to save $_POST without sending data to my server/script ?

oleevier
  • 154
  • 7
  • Your question is not clear. Please rephrase it. – waterloomatt Jul 08 '19 at 13:27
  • Where do you send anything to that other server? What's the use of that `$fields` array? – Nico Haase Jul 08 '19 at 13:29
  • 2
    Turn on error reporting - https://stackoverflow.com/a/21429652/296555. See anything? – waterloomatt Jul 08 '19 at 13:31
  • Notice double-underscore `p24__sign`. Is this throwing a warning/exception which you're not seeing because error reporting is off? – waterloomatt Jul 08 '19 at 13:32
  • @NicoHaase , good eye :) I was sending $fields before I decided to send $_POST , i should delete "curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);" and write "curl_setopt($ch, CURLOPT_POSTFIELDS, $_fields);" – oleevier Jul 08 '19 at 13:35
  • @waterloomatt , thx i will fix that underscore – oleevier Jul 08 '19 at 13:38
  • Turn on error reporting! It will find these error for you. – waterloomatt Jul 08 '19 at 13:39
  • i dont have access to php.ini :( – oleevier Jul 08 '19 at 13:52
  • You don't need to edit any other file for that, `ini_set` or `error_reporting` works fine – Nico Haase Jul 08 '19 at 13:54
  • 1
    i put to my script these lines : ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); and it doent display any errors on screen – oleevier Jul 08 '19 at 13:58
  • Perfect - you're good to go. Is your problem fixed now? If you're still having issues, edit your question with the steps you've done and the issue you're facing. – waterloomatt Jul 08 '19 at 14:07
  • ok , i dont need to get response , i want user to follow that redirecting with $_POST / sending POST makes sending back TOKEN and autoredirect to payment method with POST and TOKEN (it happens auto via https://sandbox.przelewy24.pl/trnDirect url) / later przelewy24.pl will send me important data to url_status i gave them (when user succesfuly paid) , so how can i redirect with that curl ? – oleevier Jul 08 '19 at 14:14
  • Not quite sure I follow, but sounds like you want cURL to follow redirects and pass along the request body. I can't vouch for this tutorial but the comments seem promising - https://evertpot.com/curl-redirect-requestbody/ – waterloomatt Jul 08 '19 at 14:20
  • i think my php ver is too low , none of methods found works :( / thx guys for your help , i will check again after php upgrade (5.2 right now) – oleevier Jul 10 '19 at 05:43

1 Answers1

0
  • You can make a redirect with http status 307 developer.mozilla.org/en-US/docs/Web/HTTP/Status/307 In this case also body will be redirected.
  • Another option is to do it with js, first make a request to you server, receive successful answer and then make second request using js to external URL with POST method. Maybe you will need some hidden form to do it in browser.
Anton
  • 86
  • 4
  • 1
    Can you explain all that further? That code seems to add some payment option - why should one expose that API to the end user instead of running a cURL request? – Nico Haase Jul 08 '19 at 13:30
  • i want to use przelewy24.pl as a payment method for my customers. 1. i must send specific data by POST to external url , they redirect customer to payment page and later redirect to success.php if OK. 2. for test purpose i want to save $_POST data i send/receive – oleevier Jul 08 '19 at 13:46