【问题标题】:codeigniter file_get_content or curl is not working in our dev servercodeigniter file_get_content 或 curl 在我们的开发服务器中不起作用
【发布时间】:2015-09-23 14:02:10
【问题描述】:

需要获取纬度和经度的位置详细信息, 它只是在其他服务器上工作 - 正常运行,但尝试客户端开发服务器出错,我已经尝试了大约 4 个小时 - 直到没有得到结果。协助会有所帮助。 这是我的代码:

public function index() {
    echo $this->getLocation('39.2323', '-97.3828');
}

function getLocation($lat, $long) {
    $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" . trim($lat) . "," . trim($long) . "&sensor=false";
    $json = @file_get_contents($url);
    $data = json_decode($json);
    $status = $data->status;
    $address = '';
    if ($status == "OK") {
        $address = $data->results[0]->formatted_address;
    }
    return $address;
}

收到如下错误:

遇到 PHP 错误 严重性:警告消息: file_get_contents(http://maps.googleapis.com/maps/api/geocode/json?latlng=39.2323,-97.3828&sensor=false) [function.file-get-contents]:无法打开流:连接计时 出去

文件名:webservice/Test.php 行号:17

回溯:

文件: /home/colanful/public_html/hoa/application/controllers/webservice/Test.php 行:17 函数:file_get_contents

文件: /home/colanful/public_html/hoa/application/controllers/webservice/Test.php 行:12 功能:getaddress

文件:/home/colanful/public_html/hoa/index.php 行:292 功能: 需要一次

【问题讨论】:

    标签: php codeigniter google-maps curl file-get-contents


    【解决方案1】:

    看来您需要更改客户端开发服务器上的 ini 设置。

    来自@Aillyn 的回答:

    您要查找的设置是allow_url_fopen。

    你有两种方法可以在不改变 php.ini 的情况下绕过它,一种是使用 fsockopen(),另一种是使用 cURL。

    无论如何,我建议在 file_get_contents() 上使用 cURL,因为它是为此而构建的。

    【讨论】:

    • 我也试过 curl ,没有得到结果。
    • @Wahidh:您找到解决方案了吗?如果有,请发布。
    猜你喜欢
    • 1970-01-01
    • 2018-01-11
    • 2013-09-01
    • 2019-02-15
    • 2015-02-17
    • 2012-01-12
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    相关资源
    最近更新 更多