好的我想将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.
更多推荐
发布评论