In the first file - the file I execute I have the following content:
<?php
$name = "Julia";
$article = "I like papers";
$url = "http://domain.com/process.php";
$param = array('http' => array(
'method' => 'POST',
'content' => $article
));
$mad = @stream_context_create($param);
$fp = @fopen($url, 'rb', false, $mad);
$response = @stream_get_contents($fp);
echo $response;
?>
in the second file http://domain.com/process.php I have this:
<?php
$name = $_POST["name"];
$article = $_POST["content"];
$article = $_POST["article"];
echo $article;
echo $name;
echo "Hello there</br>:
";
?>
The output that I get is just:
"Hello there"
So what is wrong, how do I pass the values $article and $name via the request and how to I extract them in the file process.php?
You got it wrong at the content part, use http_build_query()
to build the POST query.
$param = array( 'http' => array('method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded
",
'content' => http_build_query($data)
));
And your post parameters should be like below, where the input name as key
$data['name'] = 'Julia';
$data['article'] = 'I like papers';
Personally, I will use curl.