POST and PHP
Posted: Mon Jun 16, 2008 12:26 pm
Hello,
I'd like to post some data and get the result. Problem is that I have to post to remote server. Here is what i've got:
after running first.php i get: Array()muu.
Why $_Post array is empty?
Thank you,
Dj_Lord
I'd like to post some data and get the result. Problem is that I have to post to remote server. Here is what i've got:
Code: Select all
//================
//first.php
//================
<?php
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'post',
'content' => $data
));
if ($optional_headers!== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
echo do_post_request("localhost/test.php", "name1=value1&name2=value2") ;
?>Code: Select all
//=============
//test.php
//================
<?php
print_r($_POST);
echo "muu";
?>after running first.php i get: Array()muu.
Why $_Post array is empty?
Thank you,
Dj_Lord