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

时间:2019-07-08 13:07:14

标签: php forms post

我尝试将数据从FORM保存到文件。但是,当“提交”到外部URL时,我的脚本看不到$_POST array。如何保存我未收到的$_POST

我可以保存收到的$_POST数据(已发送到脚本并另存为post_array.txt)。但我必须将其发送到外部网址。 我尝试使用$_POST接收并重新发送已保存的cURL,但无法使用$_POST进行重定向。 因此,我的客户停留在我的页面上,但应使用$_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);

因为cURL无法正常工作,所以我想直接发送$ _POST做外部页面。 (效果很好,但我没有在文件中保存$ _POST) 如何保存$ _POST而不将数据发送到我的服务器/脚本?

1 个答案:

答案 0 :(得分:0)

  • 您可以使用http状态307进行重定向。developer.mozilla.org/en-US/docs/Web/HTTP/Status/307在这种情况下,正文也会被重定向。
  • 另一种方法是使用js,首先向服务器发出请求,接收成功的答案,然后使用js通过POST方法向外部URL发出第二个请求。也许您需要一些隐藏的表单才能在浏览器中执行此操作。