PHP: fopen sometimes shows HTTP headers and sometimes does not... why?

TommyWillB

Registered
Okay, I'm really confused here. I have a chunk of code the retreives a page. Reloading this multiple times produces different results...

Here is the code to retreive my page:
Code:
<?php
  $FileName="http://www.quickbase.com/";
  $FilePointer = @fopen($FileName, "r");
  $FileContents = (fread ($FilePointer, "99999999"));
  fclose ($FilePointer);
?>

<form>
		<textarea rows="30" cols="100"><?= $FileContents ?></textarea>
</form>

So what this ought to do is show the raw contents of http://www.quickbase.com/ in my form textarea... but reloading gets me different results, and I can figure out why.

Sometimes is shows just the content without any HTTP headers, like this:
Code:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
...

Sometimes it does show HTTP headers, like this:
Code:
Connection: Keep-Alive
Content-Length: 13415
Content-Type: text/html
Set-Cookie: ASPSESSIONIDSABSTSAR=MINCMPGDNCMALGCHHIPKDMBC; path=/
Cache-control: private



<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
...

Is this something I'm doing or something going on on the quickbase.com servers?
 
Not that this will affect your results, but you need to wrap the $FileContents variable like so:

<?= htmlspecialchars($FileContents) ?>
 
Back
Top