【问题标题】:Can't get to work php script using file_get_content or cURL无法使用 file_get_content 或 cURL 开始工作 php 脚本
【发布时间】:2013-06-26 19:43:20
【问题描述】:

我有这个问题。 我在这里使用这个脚本来发送一条自动短信:

<?php
function get_data($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$returned_content = get_data('http://url.goes.here:8080/bulksms/bulksms?username=user&passwd=password&type=0&dlr=1&destination=phone&source=FLM&message=hello');
?>

问题是,如果我直接提交 URL,我会得到类似:

1701|355662080090|a2406d38-1baf-42a2-a1a5-e5798859e400

我的手机收到一条短信,但如果我使用上述方法,我将收不到短信.. 任何人都可以建议我为什么会这样? 谢谢..

【问题讨论】:

  • 所以file_get_contents("http://url.goes.here:8080/bulksms/bulksms?username=user&amp;passwd=password&amp;type=0&amp;dlr=1&amp;destination=phone&amp;source=FLM&amp;message=hello") 不起作用?可能是因为allow_url_fopen 被禁用了?
  • 你能帮我解决这个问题吗?它不依赖于禁用或启用的功能..
  • 问题是,它是一个外部站点,我没有权限,我无法启用或禁用功能
  • ini_get('allow_url_open'); 的输出是什么?
  • @al_alb:另外,我们在 您的 网站中谈论allow_url_fopen

标签: php curl file-get-contents


【解决方案1】:

如果您确实在 php.ini 中激活了 allow_url_fopen,那么您应该考虑更改请求的用户代理(使用 cURL)。 许多 SMS 网关在处理其请求时使用用户代理过滤... 如果我错了,请纠正我,但我想你使用的是 RouteSMS,对吧?

【讨论】:

    猜你喜欢
    • 2016-12-17
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 2014-01-01
    • 2015-08-28
    • 2011-02-10
    • 1970-01-01
    • 2016-07-11
    相关资源
    最近更新 更多