How can I get the content of an external url like the browser does? Because when I do it with file_get_contents then the content is always different from what I can see in the browser. How can I fix that?
-
1possible duplicate of [PHP : how can use curl instead file_get_contents](http://stackoverflow.com/questions/8540800/php-how-can-use-curl-instead-file-get-contents) – Ben Lee Mar 13 '12 at 07:21
-
So far it does not look like a duplicate but it's really hard to tell anything about "it's different". – PiTheNumber Mar 13 '12 at 07:25
4 Answers
With file_get_contents
you get the same page as the browser does, unless the page does not want you too. You can try to use curl and fake a browser. Also there could be Javascript altering the page.
Provide more information about what is wrong to get more help.

- 22,828
- 17
- 107
- 180
-
I'm working on a Facebook Style URL-Extractor and for that I need to grab the data from a website by the URL. I tried curl, file_get_content, fread and fget but noone got the right side. I tried it with this URL: http://herthabsc.de/index.php?id=3631&tx_ttnews[tt_news]=12904&cHash=e19b6b9c9ff108321391693591908253 The original title is Herthas U19 im DFB-Pokalfinale but the site file_get_contents gave me said the title is Hertha BSC | News Detailseite - Adless – Jonathan Mar 13 '12 at 11:56
-
I run [this](http://codepad.org/Resxs0AV) code on my server and got: `
Hertha BSC | Herthas U19 im DFB-Pokalfinale ` like my browser does. Maybe you have a bug somethere. – PiTheNumber Mar 13 '12 at 12:21
It's because most webpages have their css
and images
locally stored, and the link to it is also locally. When a css is stored at http://www.domain.com/style.css
the link is almost everytime just style.css
without the domain. If you display the page on your website the browser will see a link to style.css
but on your website the file isn't found. To change this is you have to add http://www.domain.com/
before every link.

- 695
- 1
- 5
- 18
to get content from any file you must have to pass the physical path of the files, when browser working with the request, web server handle that
using http path... browser only dispay that file in read mode
Thanks

- 1,161
- 9
- 18