如何将信息从一个php页面传递到不同服务器的另一个页面?
我有一个php页面,比如a,在其中我调用了另一个页面,B不在同一个服务器上,使用header函数&在URL中传递一些参数。我希望从B返回一些信息给A。我如何管理这些信息?要返回的信息可能是文件或大型数组的内容 我用这个-如何将信息从一个php页面传递到不同服务器的另一个页面?,php,web,Php,Web,我有一个php页面,比如a,在其中我调用了另一个页面,B不在同一个服务器上,使用header函数&在URL中传递一些参数。我希望从B返回一些信息给A。我如何管理这些信息?要返回的信息可能是文件或大型数组的内容 我用这个- header('location:B.php?getx=23'); 现在,我需要从B向A发送一些信息。如何从B发送这些信息?我如何在同一时间收到同样的信息?从B发送的信息很敏感,无法在url中编码。我认为您可以这样工作 页面A通过url发送数据 页面B接收参数并处理数
header('location:B.php?getx=23');
现在,我需要从B向A发送一些信息。如何从B发送这些信息?我如何在同一时间收到同样的信息?从B发送的信息很敏感,无法在url中编码。我认为您可以这样工作 页面A通过url发送数据 页面B接收参数并处理数据 第B页返回数据(Json、Xml或普通html,根据您的要求) 页面A可以从请求的url解析此数据
希望它能给你一些想法。我想你可以这样工作 页面A通过url发送数据 页面B接收参数并处理数据 第B页返回数据(Json、Xml或普通html,根据您的要求) 页面A可以从请求的url解析此数据 希望它能提供一些想法。a.php页面:
header('Content-Type: text/html');// this page will send content to the web browser as html webpage
$json_string = file_get_contents('http://example.com/b.php?param=param¶m2=param2');// this is a call to the page b.php with parameters
// now, $json_string -- received from b.php data
$json = json_decode($json_string); // after decoding, $json_string converts to arrays
... // there you can do anything else
echo("<html>..."); // like send page to web browser
a.php页面:
header('Content-Type: text/html');// this page will send content to the web browser as html webpage
$json_string = file_get_contents('http://example.com/b.php?param=param¶m2=param2');// this is a call to the page b.php with parameters
// now, $json_string -- received from b.php data
$json = json_decode($json_string); // after decoding, $json_string converts to arrays
... // there you can do anything else
echo("<html>..."); // like send page to web browser
您可以使用post方法将数据发送到其他服务器
<?php
$url='http://localhost/e/admin/test.html'
$data = array ('foo' => 'bar');
function mPost($url,$data)
{
$data = http_build_query($data);
$opts = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
"Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
);
$context = stream_context_create($opts);
$html = file_get_contents($url, false, $context);
return $html;
}
?>
您可以使用post方法将数据发送到其他服务器
<?php
$url='http://localhost/e/admin/test.html'
$data = array ('foo' => 'bar');
function mPost($url,$data)
{
$data = http_build_query($data);
$opts = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
"Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
);
$context = stream_context_create($opts);
$html = file_get_contents($url, false, $context);
return $html;
}
?>
包括尝试过的解决方案、它们不起作用的原因以及预期结果。一个选项是我还没有尝试过任何东西。这就是我一直不知道如何继续的原因。包括尝试过的解决方案,为什么它们不起作用,以及预期的结果。一个选择是我还没有尝试过任何东西。这就是我一直不知道如何继续的原因。请你解释一下它是如何工作的?请你解释一下它是如何工作的?请你解释一下它是如何工作的?这个解决方案正是我需要页面做的。请你解释一下它是如何工作的?这个解决方案正是我需要页面做的。