[Solved] Post data & show source code


You can use 3rd parameter of this function: context

$postdata = http_build_query(
    array(
        'var1' => 'some content',
        'var2' => 'doh'
    )
);

$opts = array(
    'http' => array(
        'method' => "POST",
        'header' => "Connection: close\r\n".
                        "Content-Length: ".strlen($postdata)."\r\n",
        'content' => $postdata
  )
);

$context = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);

// edit -little bug should be:

$opts = array(
    'http' => array(
        'method' => "POST",
        'header' => "Connection: close\r\n".
                    "Content-type: application/x-www-form-urlencoded\r\n".
                    "Content-Length: ".strlen($postdata)."\r\n",
        'content' => $postdata
  )
);

5

solved Post data & show source code