----- Original Message -----
From: "morten"
Hello to everyone, I'm new to this group, and I've been facing a
problem I couldn't solve, I don't know how to serch for it in the
list's old messages, so I'll tell you what it is and see if you can
help me.
<snip>
*** the content of the page I'm in is "attached" to the end of the file I'm
downloading. ***
-----------------------------------
Hello morton,
You say "the content of the page I'm in is "attached" to
the end of the file I'm downloading" and I don't understand why this should
be happening.
It sounds like you are trying to re-send headers and this is not possible.
Perhaps you have white space sent first.
Headers can only be sent BEFORE the page itself even if it is only a single
space that is sent to the browser.
ie -
**** the file starts on the next line
<?php ?>
<?php header("blah");
**** the file starts on the next line
<?php header("blah");
**** the file starts on the next line
<html>
<head>
<?php header("blah");
None of the above will have the desired effect because when the server
encounters something to send to the browser it MUST send the headers first.
Once headers have been sent they cannot be resent. So any text or even a
carriage return or single space will cause problems.
If you must send headers then start the php file with <?php on the first
line and in the first position and then send the wanted headers before any
include() or include_once() as even a trailing carriage return at the end of
a included file will cause problems.
The http transaction looks like this
[header(1)]\r\n
[header(2)]\r\n
[header(n)]\r\n\r\n
[page content]\r\n
ie - the double \r\n separates the header information from the content so
the headers must be first.
The other issue with the code is things like if($_GET["download"] >= 1)
$_GET["whatever"] is a string and not a numeric value so this sort of code
can cause unpredictable results. Use one "Type" or the other and don't mix
both together - example.
if($_GET["download" == "1")
Don't use > or < for strings unless you know exactly what to expect. ie -
1 < 2 TRUE
21 < 100 TRUE
"21" < "100" FALSE - alpha numeric ordering or alphabetical order ie "2" is
greater than "1"
alternatively -
$download = intval($_GET["download"]);
if($download >= 1)...
Hope this helps.
PS: The code you sent doesn't show how pdf's are handled differently
depending on if the user wants a download or to read it in a browser plugin.