0

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.

hetelek
  • 3,776
  • 5
  • 35
  • 56

3 Answers3

2

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.)?

Community
  • 1
  • 1
JohnP
  • 49,507
  • 13
  • 108
  • 140
0

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.

robert
  • 8,459
  • 9
  • 45
  • 70
0

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.

Boann
  • 48,794
  • 16
  • 117
  • 146