简体   繁体   English

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

[英]How to save form data before sending to URL

I try to save data from a FORM to file. 我尝试将数据从FORM保存到文件。 But when 'submit' to external URL my script doesn't see $_POST array . 但是,当“提交”到外部URL时,我的脚本看不到$_POST array How to save $_POST which I send not receive. 如何保存我发送的未收到的$_POST

I can save $_POST data I received (I sent to my script and save as post_array.txt). 我可以保存收到的$_POST数据(已发送到脚本并另存为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 . 我尝试使用cURL接收并重新发送已保存的$_POST但是无法使用$_POST进行重定向。 So my customer stays on my page but should be redirected to payment page with $_POST data. 因此,我的客户停留在我的页面上,但应使用$_POST数据重定向到付款页面。

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. 因为cURL不能按预期工作,所以我想直接发送$ _POST做外部页面。 (it works well , but i dont have saved $_POST in my file) How to save $_POST without sending data to my server/script ? (效果很好,但是我没有在文件中保存$ _POST)如何保存$ _POST而无需将数据发送到服务器/脚本?

  • 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. 您可以使用http状态307进行重定向。developer.mozilla.org/en-US/docs/Web/HTTP/Status/307在这种情况下,正文也会被重定向。
  • 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. 另一种选择是使用js,首先向您的服务器发出请求,接收成功的答案,然后使用js通过POST方法向外部URL使用第二个请求。 Maybe you will need some hidden form to do it in browser. 也许您需要一些隐藏的表单才能在浏览器中进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM