您当前的位置:首页 > 计算机 > 编程开发 > PHP

将接收到的 $_POST 数据写入到一个文件中

时间:01-31来源:作者:点击数:
CDSY,CDSY.XYZ

将接收到的 $_POST 数据写入到一个文件中

// 获取 POST 数据
$recharge_server_id = $_POST['recharge_server_id'];// 充值大区
$recharge_game_id = $_POST['recharge_game_id']; // 充值序列号 
$goodstype = $_POST['goodstype']; // 商品类型 
$money_type = $_POST['money_type']; // 游戏货币类型 
$card_type = $_POST['card_type']; // 游戏卡类型 
$daybox_type = $_POST['daybox_type']; // 游戏每日礼包类型 
$box_type = $_POST['box_type']; // 游戏礼包类型 
// 将变量值连接成一个字符串 
$name = $recharge_server_id.'+'.$recharge_game_id.'+'.$goodstype.'+'.$money_type.'+'.$card_type.'+'.$daybox_type.'+'.$box_type; 
// 写入文件 
$file_path = 'post_data.txt'; 
// 指定文件路径和名称 
file_put_contents($file_path, $name); echo "POST data has been written to the file: " . $file_path;

这段代码首先获取$_POST数据并将其存储在相应的变量中。然后,它将这些变量值连接成一个字符串$name。最后,它使用file_put_contents()函数将$name字符串写入到指定的文件(在这个例子中是post_data.txt)。

notify.php中,你可以使用以下代码来从文件中读取数据:

$file_path = 'post_data.txt'; // 指定文件路径和名称 
$post_data = file_get_contents($file_path);  if ($post_data) {  $remark_list = explode("+", $post_data);   
$recharge_server_id=$remark_list[0];//充值大区  
$recharge_game_id=$remark_list[1];//充值序列号  
$goodstype=$remark_list[2];//商品类型  
$money_type=$remark_list[3];//充值货币类型  
$card_type=$remark_list[4];//游戏卡类型  
$daybox_type=$remark_list[5];//  
$box_type=$remark_list[6]; 
} else {  
echo "Error: Unable to read the file or the file is empty."; 
}
CDSY,CDSY.XYZ
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门