Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP使用file_get_contents获取页面内容时不返回任何内容_Php - Fatal编程技术网

PHP使用file_get_contents获取页面内容时不返回任何内容

PHP使用file_get_contents获取页面内容时不返回任何内容,php,Php,我试图从roblox网站获取数据,使用文件内容。我正在尝试访问“查找用户”页面: 当我请求页面时,我给出了一个名为username=[name]的get参数。然而,当我尝试加载页面时,没有返回结果 我尝试了file\u get\u contents、domdocument、curl。什么都没用。我不知道该怎么办了 <?php $User = $_GET["username"]; $Result = file_get_contents("http://www.roblox.c

我试图从roblox网站获取数据,使用文件内容。我正在尝试访问“查找用户”页面:

当我请求页面时,我给出了一个名为username=[name]的get参数。然而,当我尝试加载页面时,没有返回结果

我尝试了file\u get\u contents、domdocument、curl。什么都没用。我不知道该怎么办了

<?php
    $User = $_GET["username"];
    $Result = file_get_contents("http://www.roblox.com/search/users?keyword=".$User);
    var_dump($Result);
?>

我没有收到任何错误。仅chrome连接超时错误。

在firebug(开发工具)打开时尝试此操作:

还得再深入一点,看看发生了什么困惑。至少有一个重定向。可能正在查看
代理
或使用其他方法。也许可以看看他们是否提供了API,或者看看他们的网站条款和条件

来源显示

      _______      _________      _____       ______     _
     / _____ \    |____ ____|    / ___ \     | ____ \   | |
    / /     \_\       | |       / /   \ \    | |   \ \  | |
    | |               | |      / /     \ \   | |   | |  | |
    \ \______         | |      | |     | |   | |___/ /  | |
     \______ \        | |      | |     | |   |  ____/   | |
            \ \       | |      | |     | |   | |        | |
     _      | |       | |      \ \     / /   | |        |_|
    \ \_____/ /       | |       \ \___/ /    | |         _
     \_______/        |_|        \_____/     |_|        |_|

     Keep your account safe! Do not paste any text here.

     If someone is asking you to paste text here then you're 
     giving someone access to your account, your gear, and
     your ROBUX.

     To learn more about keeping your account safe you can go to

     https://en.help.roblox.com/hc/en-us/articles/203313380-Account-Security-Theft-Keeping-your-Account-Safe-
(嗯,似乎他们总是在每一个请求中吐露出来——尽管这是我们尝试事情的具体方式)

尽管如此,网站可能不喜欢你删除他们(你的?)的内容,并积极尝试阻止你的尝试

这里是一个屏幕截图,我从文件内容中得到了15秒的等待

只是chrome连接超时错误。 这表明您的php脚本不是失败,而是停滞。可能是http请求;因此,让我们尝试缩短超时时间:

<?php
ini_set('display_errors', true);
error_reporting(-1);

$User = $_GET["username"];
$ctx  = stream_context_create(array('http'=>array(
    'timeout'=>3.0
)));

$Result = file_get_contents(
    "http://www.roblox.com/search/users?keyword=".$User,
    false,
    $ctx
);
var_dump($Result);
?>


“没有返回结果”-意思是您得到一个空白页?当我尝试输出结果时,没有显示任何内容。您的1参数是用户名还是关键字?因为它看起来像关键字。我使用参数username调用这个php页面。我将该值作为参数关键字添加到roblox页面:它可以工作。更仔细地观察反应。它不是空的。看起来他们这边可能有点混乱。爱我一些ASCII艺术:)他们可能会提供API吗?请看:同样的结果,它仍然给出了一个chrome超时,我认为这与文件内容如何处理某些重定向有关。建议在这里使用cURL。您是否像我指定的那样打开firefox或chrome开发工具?看起来也像是在那里跳了几下-需要一分钟。将在控制台上看到输出。不管怎么说,他们真的不希望你这么做。我在chrome开发者工具中什么都没有。只有此:/deep/combinator不推荐使用。有关更多详细信息,请参阅。并不是说他们不想让我访问它。因为当我尝试获取主站点时,我没有任何问题。我在codeviper上也得到了完全相同的东西。然而,我自己的网站无法管理它?可能是我的服务器内部有什么东西阻止了它吗?可能是很多东西,他们可能在监视IPs,可能是他们看到的代理(与服务器/php版本等不同)。可能是他们想要防止刮擦,可能是某些XSS预防方案的一部分。如果你真的想了解他们在做什么,建议你试试cURL——可以调整发送的代理字符串,更好地处理重定向,使用cookie,等等……等等,刚刚发现我无法访问我网站的任何页面。我的主人可能需要维修什么的。让我在我的第二个主机服务上快速试用。