将变量发送到另一台服务器并使用PHP获取结果(Send variable to another server and get result with PHP)

编程入门 行业动态 更新时间:2024-10-26 09:30:52
将变量发送到另一台服务器并使用PHP获取结果(Send variable to another server and get result with PHP)

好的我想将PHP变量发送到另一台服务器,这是我的代码,php变量是一个ip地址。

header("Location: http://www.domainname.com/bean/data.php?ip=$ip");

基本上其他服务器将获取IP地址并返回一个名为Description的变量,我不清楚是将描述变量返回给服务器的最佳方法。

data.php页面上的代码

$ip =$_GET['ip']; include("ipology.class.php"); $ipology = new ipology( array($ip) ); $out = $ipology->out(); foreach( $out as $ip ) { if( is_array( $ip ) ) { $address = implode( ", ", (array) $ip['address'] ); $descr = implode( ", ", (array) $ip['descr'] ); echo "$descr"; } }

OK I want to send a PHP variable to another server, this is my code, the php variable is an ip address.

header("Location: http://www.domainname.com/bean/data.php?ip=$ip");

Basically the other server will get the ip address and return a variable called Description what i am unclear on is the best way to return the description variable back to the server.

code on data.php page

$ip =$_GET['ip']; include("ipology.class.php"); $ipology = new ipology( array($ip) ); $out = $ipology->out(); foreach( $out as $ip ) { if( is_array( $ip ) ) { $address = implode( ", ", (array) $ip['address'] ); $descr = implode( ", ", (array) $ip['descr'] ); echo "$descr"; } }

最满意答案

原始服务器可以使用(如Phil Cross提到的)file_get_contents或curl:

$response = file_get_contents('http://www.domainname.com/bean/data.php?ip='.$ip); print_r( $response );

远程服务器可以使用:

if ( isset( $_GET['ip'] ) && $_GET['ip'] ) { # do description lookup and 'echo' it out: }

使用标题('location:xxx'); 函数,你实际上正在做的是强制原始服务器上的PHP响应302重定向头,它将客户端发送到远程服务器,但是没有从远程服务器“返回”到原始服务器。

Originating server could use (as Phil Cross mentions) file_get_contents or curl:

$response = file_get_contents('http://www.domainname.com/bean/data.php?ip='.$ip); print_r( $response );

Remote server could use:

if ( isset( $_GET['ip'] ) && $_GET['ip'] ) { # do description lookup and 'echo' it out: }

Using the header('location: xxx'); function, what you're essentially doing is forcing PHP on the originating server to respond with a 302 redirection header which will send the client to the remote server but there's no 'going back' from the remote server to the originating.

更多推荐

本文发布于:2023-07-31 02:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   变量   另一台   服务器   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!