【发布时间】:2019-11-18 00:15:11
【问题描述】:
我尝试将数据从 FORM 保存到文件。但是当“提交”到外部 URL 时,我的脚本看不到 $_POST array。如何保存$_POST 我发送不接收。
我可以保存收到的$_POST 数据(我发送到我的脚本并保存为 post_array.txt)。但我必须将其发送到外部 url。
我尝试使用cURL 接收和重新发送已保存的$_POST,但我无法使用$_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 ?
【问题讨论】:
-
你的问题不清楚。请改写。
-
你在哪里向其他服务器发送任何东西?那个
$fields数组有什么用? -
开启错误报告 - stackoverflow.com/a/21429652/296555。看到什么了吗?
-
注意双下划线
p24__sign。这是否会引发您因为错误报告关闭而没有看到的警告/异常? -
我在脚本中添加了以下几行:ini_set('display_errors', 1); ini_set('display_startup_errors', 1);错误报告(E_ALL);它不会在屏幕上显示任何错误