我可以访问3个不同的远程服务器。它们都拥有相同的 php文件,它的名称为processing.php
。
在另一台服务器上我有3页:
index.html
:包含一个带有POST方法的表单,用于将数据发送到forward.php
forward.php
:将表单值转发给其他服务器上的processing.php
processing.php
:显示发布的数据 问题: processing.php
中的代码未执行,返回的结果是processing.php
源代码的纯文本!!
forward.php:
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
rtrim($_POST['listserver'],"-");
$listServer = explode("-",$_POST['listserver']);
foreach ($listServer as $server){
if(!empty($server)){
$url = 'http://'.$server.'/processing.php';
$data = array('field1' => $field1, 'field2' => $field2);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
echo "You can't ";
}else{
echo ('result : '.$result);
}
}
}
Processing.php
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$result = $field1+$field2;
$myFile = "files/result.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $result);
fclose($fh);
但是在所有服务器中,result.txt
都是空的!!