drba1172 2019-07-08 13:07
浏览 146

如何在发送到URL之前保存表单数据

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 ?

  • 写回答

1条回答 默认 最新

  • doudieheng5322 2019-07-08 13:27
    关注
    • 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.
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)