tags:

views:

75

answers:

6

I'm using the following code in an index.php page to display content from one page on another domain. However, it works fine in IE, but when I load the page in Firefox, its missing php data.

Am I doing something wrong or does firefox not allow this? Any help appreciated.

$domain = $_SERVER['HTTP_HOST'];
$crawl = "http://www.mysite.co.uk/page.php?domain=$domain";
$fd = fopen($crawl, "r");
while($buf = fgets($fd,1024))
{
echo $buf;
}
fclose($fd);

PLEASE NOTE: if I load the target url directly it works just fine

+1  A: 

Try view source. It might be there, and just not displayed depending on the content.

UltimateBrent
thanks, I tried that, and the data doesn't show there either.
Steven
Then I'd guess that IE is showing a cached version, and firefox is actually showing what's happening. Do you have display errors and error_reporting on? Your page my be erroring out and going white.
UltimateBrent
A: 

If you are going to view a website, do not use fopen(), use fsockopen(). However, ultimately, all of the code you have posted is server-side, so the browser should not make a difference unless there is a PHP error with $_SERVER['HTTP_POST'];

RageD
+1  A: 

In many cases such problems are caused by browser cache, and I faced with similar situation with Firefox particularly. Try cleaning it cache, then open page again.

Kel
A: 

I'm going to say that there is probably something in page.php that has a syntax error or is malformed. If you take the exact same snippet and crawl something like http://google.com, you get consistent results in all major browsers.

cinseattle
A: 

Delete the file on the server, upload this code (its nothing more than a clearer solution which doesn't require allow_url_fopen which is dangerous).

Then clear the browser caches and see if it works:

<?
$domain = $_SERVER['HTTP_HOST'];
$crawl = "http://www.mysite.co.uk/page.php?domain=$domain";

$request = curl_init($crawl);    
print curl_exec($request);
curl_close($request); 
?>

Edit: If this doesn't work, upload a file with <? echo $_SERVER['HTTP_HOST']; ?> and check if it works in both browsers.

abenthy
I tried that and it works with google as the url, but not with my target url. By the way, if I load the target url directly it works fine, that's why I'm puzzled
Steven
Can you upload a file with <? echo $_SERVER['HTTP_HOST']; ?> and tell me if it works in both browsers? `$_SERVER` seems to cause browser specific trouble to some people: http://tinyurl.com/35wp23v .
abenthy
thanks, but I've solved the problem. It was an error on my part. See my answer if you want to know more.
Steven
If I read your "answer" right, using my suggested `$_SERVER['HTTP_HOST']` you would have seen the problem, right?
abenthy
A: 

Thanks for all the responses, however it was a stupid error on my part. I was loading up the domain with www. in firefox, but without the www. in IE, hence the difference. I've added a function to strip the www. from the refering domain and now it works fine.

Steven
Please update your question or post a comment instead of posting this as an answer.
ceejayoz