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



## TommyWillB (Dec 29, 2002)

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:
	
	



```
<?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:
	
	



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

Sometimes it does show HTTP headers, like this:
	
	



```
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?


----------



## slur (Dec 31, 2002)

Not that this will affect your results, but you need to wrap the $FileContents variable like so:

*<?= htmlspecialchars($FileContents) ?>*


----------

