file_get_contents 包含哈希信息

发布于 2024-12-18 04:25:44 字数 773 浏览 1 评论 0原文

我尝试了很多方法来尝试获取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨洒年华 2024-12-25 04:25:45

哈希值不会发送到服务器。哈希部分通常只能由浏览器访问。您可能会看到某种 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.)?

浪荡不羁 2024-12-25 04:25:45

您的响应将是相同的,因为哈希值是在客户端处理的,而不是在服务器端

引用自 wikipedia

片段标识符的功能与 URI 的其余部分不同:即,它的处理完全是在客户端进行的,没有
来自服务器的参与——当然服务器通常会提供帮助
确定 MIME 类型,MIME 类型确定
片段的处理。当代理(例如 Web 浏览器)
向 Web 服务器请求资源,代理将 URI 发送到
服务器,但不发送片段。相反,代理会等待
服务器发送资源,然后代理处理
根据文档类型和片段值分配资源。

Your response will be same, since the hashes are process on the client side, not on server side

Quoted from wikipedia

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no
participation from the server — of course the server typically helps
to determine the MIME type, and the MIME type determines the
processing of fragments. When an agent (such as a Web browser)
requests a resource from a Web server, the agent sends the URI to the
server, but does not send the fragment. Instead, the agent waits for
the server to send the resource, and then the agent processes the
resource according to the document type and fragment value.

江湖彼岸 2024-12-25 04:25:45

哈希部分(称为“片段”)永远不会发送到服务器。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文