使用 PHP 的 POST 方法来接收数据

<?php
echo "page1";
$postdata = http_build_query(
    array(
        'data1' => 'hello',
        'data2' => 'world'
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);

$result = file_get_contents('page2.php', false, $context);
var_dump($result);
<?php
echo "page2";
var_dump($_POST);

从第2页看到通过$_POST接收到的数据,可以知道有data1(hello)和data2(world)。

广告
将在 10 秒后关闭
bannerAds