file_get_contents 包含哈希信息
我尝试了很多方法来尝试获取 url 的内容,并使用影响输出的哈希值。我真的不知道如何解释它,但这里有一个例子...
正在做:
echo file_get_contents('test.com/whatever.php?t1=1&t2=2#this');
将返回与以下内容相同的结果:
echo file_get_contents('test.com/whatever.php?t1=1&t2=2');
即使我在网络浏览器中导航到它,它也会产生影响。当然,上面的网址不是我正在使用的实际网址,但我希望您明白这一点。
我尝试过的事情:
CURL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
file_get_contents:
file_get_contents($url);
fread:
//don't know where I put the code.
这些都是我尝试过的事情,除了这里之外,我真的不知道下一步该去哪里。我真的不确定这是否可能,但我希望如此。
感谢您的帮助,sh042067。
I have tried many methods to try and get the contents of a url, with the hashes effecting the output. I really am not sure how to explain it, but here's an example...
Doing:
echo file_get_contents('test.com/whatever.php?t1=1&t2=2#this');
Will return the same results as:
echo file_get_contents('test.com/whatever.php?t1=1&t2=2');
Even though if I navigate to it in my web browser, it will make a difference. Of course the urls above aren't the actual one's that I am using, but I hope you get the point.
Things I have tried:
CURL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
file_get_contents:
file_get_contents($url);
fread:
//don't know where I put the code.
Those are all the things I have tried, and don't really know where to go next besides here. I'm really not sure if this is even possible, but I hope it is.
Thanks for any help, sh042067.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
哈希值不会发送到服务器。哈希部分通常只能由浏览器访问。您可能会看到某种 AJAX 检索正在运行,因此您需要找出正在调用的实际 URL 并使用它。您可以使用 Firebug 来实现此目的。
找到参考文献:http://en.wikipedia.org/wiki/Fragment_identifier
也检查这些
为什么URL的哈希部分不在服务器端?
我可以在服务器端应用程序(PHP、Ruby、Python 等)上读取 URL 的哈希部分吗?
Hashes are not sent to the server. The hash part is usually only accessed by the browser. Yo're probably seeing some kind of AJAX retrieval in action so you'll need to find out the actual URL that is being called and use that instead. You could use Firebug for this.
Found the references : http://en.wikipedia.org/wiki/Fragment_identifier
Check these too
Why the hash part of the URL is not in the server side?
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
您的响应将是相同的,因为哈希值是在客户端处理的,而不是在服务器端
引用自 wikipedia
Your response will be same, since the hashes are process on the client side, not on server side
Quoted from wikipedia
哈希部分(称为“片段”)永远不会发送到服务器。 HTTP 协议中没有有效的方法来做到这一点。该片段仅用于页面内的导航,但浏览器无论如何都会请求和接收相同的数据。
一些网站使用 JavaScript 管理片段,以发出异步请求来加载新数据并动态更改页面,这在一定程度上模糊了界限。
在您的情况下,您必须在页面上找到具有
id="this"
的 HTML 元素,因为这是片段指向的位置,也是浏览器向下滚动到的位置。或者,如果您得到一个看起来像查询变量的片段,您将必须找到您尝试请求的真实的非 JavaScript URL。The hash part (called the 'fragment') is never sent to a server. There's no valid way in the HTTP protocol to do it. The fragment is only for navigation within the page, but the browser requests and receives the same data regardless.
Some sites manage the fragment with JavaScript to issue asynchronous requests to load new data and alter the page dynamically, which blurs the line somewhat.
In your case you'll have to find the HTML element on the page which has an
id="this"
because that's where the fragment points and it's where the browser would scroll down to. Or if you get a fragment that looks like query variables you'll have to find the real, non-JavaScript URL of what you're trying to request.