清空$ _POST变量webservice响应

时间:2012-10-03 15:51:49

标签: php html web-services post get

我正在与网络服务服务器通信,在付款完成后,服务器会将响应作为$_POST变量发送给我。如果我尝试print_r($_POST)它似乎是空的,但是当我将变量写入文本文件时,该文件会显示值。我的目标是构建一个执行链接来完成用户的订单。由于$ _POST值仅在文本文件中可见,我正在从文本文件中读取链接并尝试执行重定向,但是当到达另一页时,$ _GET变量为空。我之前尝试使用file_get_contents("php://input")恢复原始$ _POST变量但没有成功。这是我的实际代码:

<?php   
ob_start();
// let's get the online response parameters...  
$_VTransactionID = $_POST["VTransactionID"];
$_VAccountId = $_POST["VAccountId"];
$_VTotalAmount = $_POST["VTotalAmount"];
$_VPaymentMethod = $_POST["VPaymentMethod"];
$_VPaymentDescription = $_POST["VPaymentDescription"];
$_VAuthorizationNum = $_POST["VAuthorizationNum"];
$_VConfirmationNum = $_POST["VConfirmationNum"];
$_VMerchantTransId = $_POST["VMerchantTransId"];

////////Write LInk to file////////////////////////////////////
$fp = fopen("debug/OnlineResponseLog.log","w");

$link = "testvar.php?order_id=".$_VAccountId."&code=000&error=false&TxnGUID=".$_VConfirmationNum."\n\r";

if($fp){
    fwrite($fp,$link);
    fclose($fp);
}else{
    printf("error while trying to write on online response Log");
}
////////////////////////////////////////////////////////////////////////////
/////REad LINK////////////////////////////////////////////////////
$fp = fopen("debug/OnlineResponseLog.log","r");
if($fp){
    $cad = fread($fp,filesize("debug/OnlineResponseLog.log"));
    fclose($fp);
}else{
    printf("error while trying to read online response Log");
}
////////////////////////////////////////////////////
$url = $cad;
//To check if values where stored. Last char is used because last characters are supposed to be digits and not an equal sign.
$lastchar = substr($url, -1);
if($lastchar == "=")  
         $url ="testvar.php?order_id=&code=999&error=true&TxnGUID="; 

header("Location: $url");
//////////////////  
?>

任何帮助将不胜感激。如果在$_POST

处显示print_r($_POST);值,则可以避免所有文件写入

3 个答案:

答案 0 :(得分:0)

使用$_REQUEST全局变量。仅当数据被发布时才会填充$_POST变量&#34;仅在发送HTTP查询字符串时填充$_GET。两种方法都填充了$_REQUEST。但是,在FORM发布期间,您应该更加警惕插入攻击,因此在使用$_REQUEST时,用户重要性的卫生/验证仍然至关重要。

答案 1 :(得分:0)

我猜你的帖子变量不是空的......你因为这个而无法看到任何内容

ob_start();

在测试时删除该功能

答案 2 :(得分:0)

我通过将两个单独的php文件中的任务分开来解决了这个问题。一个文件将带有$ _POST变量的构造链接写入文件,并重定向到第二个文件,该文件从文件中读取链接并重定向到相应的页面。

相关问题