Error using file_get_contents in PHP
Has anybody seen this before. If I go to a page (http://thamessailingclub.co.uk/news.php?Type=News&Source=Google%20Boating%20News) and look at the page source, there are no errors. However, if retrieve the url in PHP using:
file_get_contents($url) ;
...there are (SQL) errors on the page! Weird how can the S开发者_高级运维QL return errors in one case and not the other? This is breaking my test suite.
90% of probabilty it's an issue related to HTTP Headers. file_get_contents doesn't send all the headers that a browser do and that could broke some query.
Perhaps the site checks the user agent, and has a bug when serving up content for something other than Mozilla Firefox, Microsoft IE, etc. You could change your PHP user agent with the following:
ini_set('user_agent', 'agent_name');
Does your browser contain some kind of session cookie that is affecting the page you are loading? Does the page need you to be logged in for instanace?
精彩评论