File_get_contents没有返回结果

时间:2013-05-23 00:23:29

标签: php

我有以下代码,它将IP地址发送到另一台服务器上的页面,然后处理该IP地址并返回描述。

问题是我没有错误,但代码没有返回结果。

发送IP地址的代码

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

获取IP地址,处理并返回结果的代码。

 if ( isset( $_GET['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";   

} }}

1 个答案:

答案 0 :(得分:0)

您目前没有将IP地址传递给网址,而是传递文字$ip_address。这是因为您使用单引号'作为网址。如果要将变量传递给字符串,请使用双引号"

$response = file_get_contents("http://www.domain.com/bean/ripe.php?ip=$ip_address");