如何发布数据到另一个文件在php


how to post data to another file in php

在这方面需要帮助1. 我需要设计一个用户输入表单,它有三个文本字段说T1, T2, T3。2. 现在,这三个文件的输入应该打包到encode_json中3.我有一个表的多行,与自动增量id 1,2,3,4等。现在,应该将相同的编码json消息与id和编码json消息一起传递到文件send_message.php。这里是send_message.php

<?php
if (isset($_GET["regId"]) && isset($_GET["message"])) {
    $regId = $_GET["regId"];
    $message = $_GET["message"];
    include_once './GCM.php';
    $gcm = new GCM();
    $registatoin_ids = array($regId);
    $message = array("price" => $message);
    $result = $gcm->send_notification($registatoin_ids, $message);
    echo $result;
}
?>

对于表相关的循环和行计数,您可以使用以下

if ($no_of_users > 0) {
                    ?>
                    <?php
                    while ($row = mysql_fetch_array($users)) {

也许cURL是你正在寻找的东西。对于每一行,您都可以打开到send_message.php的连接并传递您想要的数据。

否则你可以只包括send_message.php,但我不建议这样做。

编辑根据您的要求,这里有一个非常基本的示例:

<?php
$curlPostfields = array(
    'field1'=>$value1,
    'field2'=>$value2,
);
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, 'send_message.php');
curl_setopt($curlHandler, CURLOPT_HEADER, false);
curl_setopt($curlHandler, CURLOPT_POST, true);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $curlPostfields);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curlHandler);

你可以把它打包到一个自己的函数中,然后对表格的每一行调用这个函数