Re: HTTP_REFERER vs. session_whatever() vs. header()

From: Date: Thu, 25 Jan 2001 02:52:29 +0000
Subject: Re: HTTP_REFERER vs. session_whatever() vs. header()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36548@lists.php.net to get a copy of this message
> // echo $test."<br>"; > "//" . Without the remark, the code work but I get the error message > stating .... > > Warning: Cannot add header information - headers already sent by (output > started at test.php) in test.php on line ** Yes. A header is called a header because it comes out ahead of the actual page content. So what your browser *REALLY* sees is stuff like this: ------------------------ Content-type: text/html Content-length: 1035 Expiration: Jan 14 2001 20:46:37 GMT Cookie: user_id "a7fjeju48dj934jdjcu8" <HTML> <BODY>test</BODY> </HTML> ------------------------ Note the blank line between the headers and the HTML tag. That innocent blank line is very, very significant. It signifies the *END* of the headers and the beginning of the content. So, here's the deal. When you print something out, or have an HTML tag, or have a blank line, PHP has to send that out as part of the Content. Now, in order to do that, PHP has to send out your headers first, then the blank line, then whatever your content is. If you later try to send out a header, using the http://php.net/header function, or http://php.net/setcookie or http://php.net/session-start (sessions use cookies to track users), IT IS TOO LATE. That boat already sailed. Once the headers go out, and the blank line after them, you can't get more headers to be in front of that blank line that signified the end of the headers. > When I put in the remark, the 2nd file, test.php couldn't use > $GLOBAL["HTTP_REFERER"] because it couldn't find the last file. I was > thinking that maybe the HTTP_REFERER couldn't reach the last file because of > the way the header work. What exactly are you trying to do with the referer in the 2nd file? Print it? What? Why?

« previous php.general (#36548) next »