Re: [PHP] HTTP headers and include()

2009-07-12 Thread Lenin
On Fri, Jul 10, 2009 at 12:49 PM, Michael A. Peters mpet...@mac.com wrote:

 James Colannino wrote:



 White space can cause this - make sure your code has ?php as the very top
 and ? at the very bottom, or the white space may trigger the web server to
 send a header and the white space as data before the cookie for
 session_start() is sent.



Well, at the end of the file dont put a ? on your php files especially
which files you are gonna include at others. It would save you some
dreadfull buggy times. Its also practiced in the framework programming.


Re: [PHP] HTTP headers and include()

2009-07-12 Thread Ashley Sheridan
On Sunday 12 July 2009 12:01:12 Lenin wrote:
 On Fri, Jul 10, 2009 at 12:49 PM, Michael A. Peters mpet...@mac.com wrote:
  James Colannino wrote:
 
 
 
  White space can cause this - make sure your code has ?php as the very
  top and ? at the very bottom, or the white space may trigger the web
  server to send a header and the white space as data before the cookie for
  session_start() is sent.

 Well, at the end of the file dont put a ? on your php files especially
 which files you are gonna include at others. It would save you some
 dreadfull buggy times. Its also practiced in the framework programming.

Well, some frameworks insist on it being in there. I tend to always include 
them, but I use a text editor that I know won't add characters to the end 
after the final ?

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTTP headers and include()

2009-07-12 Thread tedd

At 12:09 PM +0100 7/12/09, Ashley Sheridan wrote:

On Sunday 12 July 2009 12:01:12 Lenin wrote:

 On Fri, Jul 10, 2009 at 12:49 PM, Michael A. Peters mpet...@mac.com wrote:
  James Colannino wrote:
 
 
 
  White space can cause this - make sure your code has ?php as the very
  top and ? at the very bottom, or the white space may trigger the web
  server to send a header and the white space as data before the cookie for
  session_start() is sent.

 Well, at the end of the file dont put a ? on your php files especially
 which files you are gonna include at others. It would save you some
 dreadfull buggy times. Its also practiced in the framework programming.


Well, some frameworks insist on it being in there. I tend to always include
them, but I use a text editor that I know won't add characters to the end
after the final ?

--
Thanks,
Ash


Ash:

I do the same. It would brother me (lack of symmetry) if I didn't 
include a ? at the end of my scripts.


As for additional characters after the ?, I make sure my 
terminations don't have any. Just because characters can be white 
space doesn't mean you can't detect them.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTTP headers and include()

2009-07-12 Thread Zareef Ahmed
On Fri, Jul 10, 2009 at 12:54 PM, James Colannino ja...@colannino.orgwrote:

 Eddie Drapkin wrote:

  HTTP headers are sent and finalized after the first bit of output.   I
  had the same problem before and it turned out to be because I had a
  close tag ? at the end of a file followed by some whitespace.  The
  solution was to remove the ? from the end of all the files and I
  haven't closed an entire file since.  Perhaps that might be it?

 Hmm...  In fact, I did close all my include files with the ? tag, and
 per Michael's observation in another response, there is a line of
 whitespace after the closing tag in my include files.

 I tried getting rid of the trailing whitespace, and removed the closing
 tags.  Unfortunately, even after that, when I place my include files
 before session_start, I get the same problem.  There's no leading
 whitespace before the starting ?php tag, so I'm still a little at a loss.

 It's not too big of a deal though; I simply placed my include files
 after the call to session_start().  That seems to solve the problem.


That's a good practice, (Although not optimal is some application setups )
but I am wondering why you are not getting information about exact place
where output is being started.
You should get a headers already sent output started at  kind of error
if you have enabled error reporting with display_errors ON.



 James

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net


Re: [PHP] HTTP headers and include()

2009-07-12 Thread James Colannino
Zareef Ahmed wrote:

 You should get a headers already sent output started at  kind of error
 if you have enabled error reporting with display_errors ON.

Actually, I did.  I just didn't think to mention it in my first post.
The thing was that it said it was coming from one of my includes, even
though I wasn't yet printing anything to the browser.  That's why I was
so confused.

I've been following what tedd said in an earlier post (to make
session_start() your first line of code) and haven't had a problem since.

James


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTTP headers and include()

2009-07-12 Thread Zareef Ahmed
On Sun, Jul 12, 2009 at 11:27 PM, James Colannino ja...@colannino.orgwrote:

 Zareef Ahmed wrote:

  You should get a headers already sent output started at  kind of
 error
  if you have enabled error reporting with display_errors ON.

 Actually, I did.  I just didn't think to mention it in my first post.
 The thing was that it said it was coming from one of my includes, even
 though I wasn't yet printing anything to the browser.  That's why I was
 so confused.


Its not only print or echo command which may output.
 As Michael was pointing even a space can cause this problem.
Your error message will tell you about exact location of the problem spot
with line number.

(If you are only getting this problem after uploading your code to server
then your FTP client may be culprit)




 I've been following what tedd said in an earlier post (to make
 session_start() your first line of code) and haven't had a problem since.


Yes, its a good practice for almost all applications and you should do it
always unless you have a reason to do otherwise.
If its really hard to maintain (like working with older codebase with lots
of references to session_start in the middle of application process) then
just putting ob_start at very start of application can also solve the
problem.


 James


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net


Re: [PHP] HTTP headers and include()

2009-07-10 Thread James Colannino
Eddie Drapkin wrote:

 HTTP headers are sent and finalized after the first bit of output.   I
 had the same problem before and it turned out to be because I had a
 close tag ? at the end of a file followed by some whitespace.  The
 solution was to remove the ? from the end of all the files and I
 haven't closed an entire file since.  Perhaps that might be it?

Hmm...  In fact, I did close all my include files with the ? tag, and
per Michael's observation in another response, there is a line of
whitespace after the closing tag in my include files.

I tried getting rid of the trailing whitespace, and removed the closing
tags.  Unfortunately, even after that, when I place my include files
before session_start, I get the same problem.  There's no leading
whitespace before the starting ?php tag, so I'm still a little at a loss.

It's not too big of a deal though; I simply placed my include files
after the call to session_start().  That seems to solve the problem.

James

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTTP headers and include()

2009-07-10 Thread kranthi
a single line break after the closing ? will not cause this problem. PHP
interpreter will neglect a single line break after ? a good debugger like
xdebug will be helpful in this case. u can also see the source code of the
file to locate the output. any thing before php warning is the output before
session_start()


Re: [PHP] HTTP headers and include()

2009-07-10 Thread Michael A. Peters

tedd wrote:

At 12:24 AM -0700 7/10/09, James Colannino wrote:

Eddie Drapkin wrote:


 HTTP headers are sent and finalized after the first bit of output.   I
 had the same problem before and it turned out to be because I had a
 close tag ? at the end of a file followed by some whitespace.  The
 solution was to remove the ? from the end of all the files and I
 haven't closed an entire file since.  Perhaps that might be it?


Hmm...  In fact, I did close all my include files with the ? tag, and
per Michael's observation in another response, there is a line of
whitespace after the closing tag in my include files.

I tried getting rid of the trailing whitespace, and removed the closing
tags.  Unfortunately, even after that, when I place my include files
before session_start, I get the same problem.  There's no leading
whitespace before the starting ?php tag, so I'm still a little at a 
loss.


It's not too big of a deal though; I simply placed my include files
after the call to session_start().  That seems to solve the problem.

James



James:

As I understand things, that's the way it is supposed to work -- you 
always start a session page off with session_start() as your first 
statement.


I've had some pages complain that a session has already been started and 
in that case, I check to see if a session ID is set and it not, then do 
a session_start().


 But, as a matter of habit, I always make session_start() my first line 
of code.


Cheers,

tedd



If the included file has

?php
somefunc() {
  }
?

?php
somefunc() {
  }
?

that will also cause it.
Or maybe one of the include files includes a file (IE db connection 
script) that has white space.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] HTTP headers and include()

2009-07-09 Thread James Colannino
Hey everyone,

I've been hard at work on a new web application, and discovered
something that I would never have seen coming.  I was noticing that when
I called session_start() after a few lines of includes, I was getting
complaints because the HTTP headers had already been sent out.  Then,
after putting session_start() above the include lines, suddenly
everything was working fine.

The files that were included were nothing more than functions; there was
no code executing that I could tell up to the point of the call to
session_start().

I was just wondering if anybody on the list knows why HTTP headers were
being sent out by my includes.  I'm sure there's a good reason.  I'm
just very curious :)

Thanks very much in advance.

James

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTTP headers and include()

2009-07-09 Thread Eddie Drapkin
On Fri, Jul 10, 2009 at 1:21 AM, James Colanninoja...@colannino.org wrote:
 Hey everyone,

 I've been hard at work on a new web application, and discovered
 something that I would never have seen coming.  I was noticing that when
 I called session_start() after a few lines of includes, I was getting
 complaints because the HTTP headers had already been sent out.  Then,
 after putting session_start() above the include lines, suddenly
 everything was working fine.

 The files that were included were nothing more than functions; there was
 no code executing that I could tell up to the point of the call to
 session_start().

 I was just wondering if anybody on the list knows why HTTP headers were
 being sent out by my includes.  I'm sure there's a good reason.  I'm
 just very curious :)

 Thanks very much in advance.

 James

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



HTTP headers are sent and finalized after the first bit of output.   I
had the same problem before and it turned out to be because I had a
close tag ? at the end of a file followed by some whitespace.  The
solution was to remove the ? from the end of all the files and I
haven't closed an entire file since.  Perhaps that might be it?

--Eddie

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTTP headers and include()

2009-07-09 Thread Michael A. Peters

James Colannino wrote:

Hey everyone,

I've been hard at work on a new web application, and discovered
something that I would never have seen coming.  I was noticing that when
I called session_start() after a few lines of includes, I was getting
complaints because the HTTP headers had already been sent out.  Then,
after putting session_start() above the include lines, suddenly
everything was working fine.

The files that were included were nothing more than functions; there was
no code executing that I could tell up to the point of the call to
session_start().

I was just wondering if anybody on the list knows why HTTP headers were
being sent out by my includes.  I'm sure there's a good reason.  I'm
just very curious :)

Thanks very much in advance.

James



White space can cause this - make sure your code has ?php as the very 
top and ? at the very bottom, or the white space may trigger the web 
server to send a header and the white space as data before the cookie 
for session_start() is sent.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTTP headers and include()

2001-08-23 Thread Christian Reiniger

On Thursday 23 August 2001 02:36, Casteele/ShadowLord wrote:
 Andy [EMAIL PROTECTED] wrote in article

   See if is there some kind of echo before header()s, or HTML sent to
  browser.

 No, I've been extremely careful to avoid that.  The following are the
 two test files I've been using to try to solve this..  (sans the

 if( headers_sent ) {
 $senthdrs = Headers Sent;
 } else {
 $senthdrs = Headers not sent;
 }

does it make a difference if you use the proper function call syntax 
(i.e. ad the () brackets after headers_sent) ?

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

Install once, run forever. Linux.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] HTTP headers and include()

2001-08-22 Thread Casteele/ShadowLord

I've written a separate function library for a cluster of web pages, and I
then include(slib.php) in each of the web pages, instead of copying 12k
of code to each page individually.  Some of the pages require (simple)
authentication or redirection headers, which some of the code in the
library is supposed to handle.

Problem is, when I include the library, even though there's no other output
to be processed, it still generates the linefeed that triggers sending all
the current headers, so if(!headers_sent) {...} fails.

Is it possible to include php code without sending headers?  I've tried
exit() within the library, but that fails to work.  Instead, exit causes
generation of HTML code (a content type metatag) that is neither in the
main page nor the library.  I've also tried a simple return() (per the
documentation), but that generates a parse error.

I'm using Apache 1.3.12, PHP 4.0.2 and Slackware Linux (Not sure which
kernel version).

Thanks
Cas

PS: Please CC replies to [EMAIL PROTECTED], since I'm not officially
subscribed to this list.  Thanks.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] HTTP headers and include()

2001-08-22 Thread Andy





 See if is there some kind of echo before header()s, or HTML sent to
browser.
 You cannot do this
 html
 head
  Bla bla
 ?php header(Location : any_script.php\n\n);?
 /head
 body
 
/body
 /html
 Why? Because there is already content sent to the browser. If some code
uses
 header() place it before any output. As I said sometimes a simple echo()
 breaks all.

 Andrey Hristov
 IcyGEN Corporation
 http://www.icygen.com
 99%

 - Original Message -
 From: Casteele/ShadowLord [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Wednesday, August 22, 2001 6:52 PM
 Subject: [PHP] HTTP headers and include()


  I've written a separate function library for a cluster of web pages, and
I
  then include(slib.php) in each of the web pages, instead of copying
12k
  of code to each page individually.  Some of the pages require (simple)
  authentication or redirection headers, which some of the code in the
  library is supposed to handle.
 
  Problem is, when I include the library, even though there's no other
 output
  to be processed, it still generates the linefeed that triggers sending
all
  the current headers, so if(!headers_sent) {...} fails.
 
  Is it possible to include php code without sending headers?  I've tried
  exit() within the library, but that fails to work.  Instead, exit causes
  generation of HTML code (a content type metatag) that is neither in the
  main page nor the library.  I've also tried a simple return() (per the
  documentation), but that generates a parse error.
 
  I'm using Apache 1.3.12, PHP 4.0.2 and Slackware Linux (Not sure which
  kernel version).
 
  Thanks
  Cas
 
  PS: Please CC replies to [EMAIL PROTECTED], since I'm not officially
  subscribed to this list.  Thanks.
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] HTTP headers and include()

2001-08-22 Thread Casteele/ShadowLord



Andy [EMAIL PROTECTED] wrote in article
003b01c12b23$d1f245d0$0b01a8c0@ANDreY...

  See if is there some kind of echo before header()s, or HTML sent to
 browser.

No, I've been extremely careful to avoid that.  The following are the two
test files I've been using to try to solve this..  (sans the --
File Begin/End --)

lib.php:
-- File Begin --
?php
function do_nothing() {}
?
-- File End --

test.php
-- File Begin --
?php
include_once(lib.php);
if( headers_sent ) {
$senthdrs = Headers Sent;
} else {
$senthdrs = Headers not sent;
}
?html
headtitlePHP Lib Test/title/head
bodyh1PHP Lib Test/h1hr
?php
echo( $senthdrs );
?/body
/html
-- File End --

End result:
PHP Lib Test

Headers sent


From what I can tell from the documentation and through experimentation,
either there's additional headers being generated when php includes the
content (a content-type header maybe?) or more likely, after php is done
parsing the file and 'removing' the code, it comes back as a single CRLF,
which triggers Apache/PHP to send the headers.  Actually, that setup makes
sense to me, but I'm trying to find out if there is a way around it.

Thanx
Cas


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] HTTP headers and include()

2001-08-22 Thread David Robley

On Thu, 23 Aug 2001 10:06, Casteele/ShadowLord wrote:
 Andy [EMAIL PROTECTED] wrote in article
 003b01c12b23$d1f245d0$0b01a8c0@ANDreY...

   See if is there some kind of echo before header()s, or HTML sent to
  browser.

 No, I've been extremely careful to avoid that.  The following are the
 two test files I've been using to try to solve this..  (sans the
 -- File Begin/End --)

 lib.php:
 -- File Begin --
 ?php
 function do_nothing() {}
 ?
 -- File End --

 test.php
 -- File Begin --
 ?php
 include_once(lib.php);
 if( headers_sent ) {
 $senthdrs = Headers Sent;
 } else {
 $senthdrs = Headers not sent;
 }
 ?html
 headtitlePHP Lib Test/title/head
 bodyh1PHP Lib Test/h1hr
 ?php
 echo( $senthdrs );
 ?/body
 /html
 -- File End --

 End result:
 PHP Lib Test
 
 Headers sent


 From what I can tell from the documentation and through
 experimentation, either there's additional headers being generated when
 php includes the content (a content-type header maybe?) or more likely,
 after php is done parsing the file and 'removing' the code, it comes
 back as a single CRLF, which triggers Apache/PHP to send the headers. 
 Actually, that setup makes sense to me, but I'm trying to find out if
 there is a way around it.

 Thanx
 Cas

Check your included file for _ANY_ blank lines outside the ?php tags. 
That will be enough to trigger the problem.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   How long will a floating point operation float?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]