RE: [PHP] headers already sent and cookie problem

2003-07-18 Thread Ford, Mike [LSS]
-Original Message-
From: frederik feys
To: 'Ford, Mike   [LSS]'; [EMAIL PROTECTED]

Here's the URL:
http://www.aurelis.org/store/cart.txt
and the get_cartID:
http://www.aurelis.org/store/includes/functions/get_cartID.txt

--

I've only had time for a quick look, but I think I have an inkling of where
your problem might be.

It all seems to lie with the way you've implemented GetCartId() -- and the
problem will only show up any time the cartId cookie is not already set.
Basically, if the cookie is not set, GetCartId() generates a new ID and sets
the cookie -- but this requires sending a header, and you can't do this once
you've started output of the real page.  So you must make you first call to
GetCartId() *before* you send any output.  Now, if we look at this fragment
of code from /store/cart.txt:

  function ShowCart($lang)
  {
  global
$connection,$lang_dir,$DOCUMENT_ROOT,$page_theme,$country_iso_code,$srch_ter
m;

  /* ob_start(); //start buffering output */

  $page_title=get_label(194,$lang,$connection);
  $page_tab=3;
  include_once($DOCUMENT_ROOT . /header_aurelis.php); 
 

  $country_iso_code = $_GET[country_iso_code]; 

  if($lang==EN){
$currency_symbol = $ ;
}
  else{ 
$currency_symbol = euro; ; 
}

  $totalCost = 0;
  $show_cart = @mysql_query((select * from cart inner join items on
cart.itemId = items.itemId where cart.cookieId = ' . GetCartId() . ' order
by items.itemName asc),$connection);

... we can see that you include header_aurelis.php, which presumably outputs
the initial part of your HTML, before you do

  $show_cart = @mysql_query ... ;

which includes a call to GetCartId() -- which will attempt to set the cartId
cookie if it's not already set, and will fail with the headers already
sent error.

So, overall, I'd say you've got to get/set your cartId earlier in the game
-- and certainly before you call or include anything that outputs actual
page content.

This analysis also explains why the error is intermittent -- someone who has
set the cartId cookie once will probably not see the error again until after
the cookie expires 30 days later!

Hope this helps (and you followed my somewhat rambling explanation!)

Cheers!

Mike

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



RE: [PHP] headers already sent and cookie problem

2003-07-18 Thread frederik feys
Hi Mike, hi all,

I solved this nasty one! Happy. Your analysis is totally correct, Mike.
Every visitor who puts an item in cart for the first time will get a
cookie and... receives the error on his screen. And I, ... I didn't have
this error message! 
What did it for me was:
?
session_start();

include_once(../Connections/Aurelis.php); 
include_once($DOCUMENT_ROOT . /includes/functions/get_label.php); 
include_once($DOCUMENT_ROOT . /includes/functions/countries.php);  
include_once($DOCUMENT_ROOT .
/store/includes/functions/calculate_shipping.php); 
include_once($DOCUMENT_ROOT .
/store/includes/functions/get_cartID.php);

$cookie = GetCartId();

-- so , i just called the function and assigned it to a variable and...
gone with the wind!

Thanks again Mike!

Regards
Fred



-Original Message-
From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] 
Sent: vrijdag 18 juli 2003 18:20
To: 'frederik feys '; '[EMAIL PROTECTED] '
Subject: RE: [PHP] headers already sent and cookie problem


-Original Message-
From: frederik feys
To: 'Ford, Mike   [LSS]'; [EMAIL PROTECTED]

Here's the URL:
http://www.aurelis.org/store/cart.txt
and the get_cartID:
http://www.aurelis.org/store/includes/functions/get_cartID.txt

--

I've only had time for a quick look, but I think I have an inkling of
where
your problem might be.

It all seems to lie with the way you've implemented GetCartId() -- and
the
problem will only show up any time the cartId cookie is not already set.
Basically, if the cookie is not set, GetCartId() generates a new ID and
sets
the cookie -- but this requires sending a header, and you can't do this
once
you've started output of the real page.  So you must make you first call
to
GetCartId() *before* you send any output.  Now, if we look at this
fragment
of code from /store/cart.txt:

  function ShowCart($lang)
  {
  global
$connection,$lang_dir,$DOCUMENT_ROOT,$page_theme,$country_iso_code,$srch
_ter
m;

  /* ob_start(); //start buffering output */

  $page_title=get_label(194,$lang,$connection);
  $page_tab=3;
  include_once($DOCUMENT_ROOT . /header_aurelis.php); 
 

  $country_iso_code = $_GET[country_iso_code]; 

  if($lang==EN){
$currency_symbol = $ ;
}
  else{ 
$currency_symbol = euro; ; 
}

  $totalCost = 0;
  $show_cart = @mysql_query((select * from cart inner join items on
cart.itemId = items.itemId where cart.cookieId = ' . GetCartId() . '
order
by items.itemName asc),$connection);

... we can see that you include header_aurelis.php, which presumably
outputs
the initial part of your HTML, before you do

  $show_cart = @mysql_query ... ;

which includes a call to GetCartId() -- which will attempt to set the
cartId
cookie if it's not already set, and will fail with the headers already
sent error.

So, overall, I'd say you've got to get/set your cartId earlier in the
game
-- and certainly before you call or include anything that outputs actual
page content.

This analysis also explains why the error is intermittent -- someone who
has
set the cartId cookie once will probably not see the error again until
after
the cookie expires 30 days later!

Hope this helps (and you followed my somewhat rambling explanation!)

Cheers!

Mike

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



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

RE: [PHP] headers already sent and cookie problem

2003-07-17 Thread frederik feys
Hi all, hi Mike,

Here's the URL:
http://www.aurelis.org/store/cart.txt
and the get_cartID:
http://www.aurelis.org/store/includes/functions/get_cartID.txt

Thanks in advance!
Fred

-Original Message-
From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] 
Sent: woensdag 16 juli 2003 12:20
To: 'frederik feys'; [EMAIL PROTECTED]
Subject: RE: [PHP] headers already sent and cookie problem

 -Original Message-
 From: frederik feys [mailto:[EMAIL PROTECTED]
 Sent: 16 July 2003 10:21
 
 One nasty thing to debug is that the error only shows up from time to
 time.
 So now everything seems OK.
 
 What do i have now?
 I start my code with session_start
 Then include some files. The last one is get_cartID.php (remember?)
 Then i use several functions to have cart functionallity.
 In show_cart i include my page heading and then output 
 further body and
 footer content.
 When I put the get_cartID include file AFTER include 
 heading.php into
 my show cart function, the other functions start complaining 
 they can't
 access the function get_cartID.
 Lots of text, sorry for that. But I still don't have the clue.
 Maybe you like to see my code?

Yes, I think so -- I can't visualize enough of what's going on from your
description to make further suggestions about what you might need to
look
at.

From the sound of it, your files are quite big, so the best thing would
be
if you can put them up (as .phps or .txt) on your Web server and post
their
URLs to the list.  If you can't do that, attach them to an email as .txt
files.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211


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

RE: [PHP] headers already sent and cookie problem

2003-07-16 Thread frederik feys
Thanks for your tips Mike!

One nasty thing to debug is that the error only shows up from time to
time.
So now everything seems OK.

What do i have now?
I start my code with session_start
Then include some files. The last one is get_cartID.php (remember?)
Then i use several functions to have cart functionallity.
In show_cart i include my page heading and then output further body and
footer content.
When I put the get_cartID include file AFTER include heading.php into
my show cart function, the other functions start complaining they can't
access the function get_cartID.
Lots of text, sorry for that. But I still don't have the clue.
Maybe you like to see my code?

Any help welcome!
Fred
 

-Original Message-
From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] 
Sent: dinsdag 15 juli 2003 11:36
To: 'frederik feys'; [EMAIL PROTECTED]
Subject: RE: [PHP] headers already sent and cookie problem

 -Original Message-
 From: frederik feys [mailto:[EMAIL PROTECTED]
 Sent: 15 July 2003 09:45
  
 This is what i get:
 Warning: Cannot add header information - headers already 
 sent by (output started at /home/u/r/html/store/cart.php:188) 
 in /home/u/r/html/store/includes/functions/get_cartID.php on line 14

This says that on line 188 of store/cart.php you started outputting your
HTML page, but you can't do that before the attempt to send headers on
line 14 of store/includes/functions/get_cartID.php.  Take a good look at
line 188 of store/cart.php to see what you can do so that it is not
starting HTML output, or move the header calls above the point where it
is included/required.

 I know that the problem is the reading of the cookie and then 
 after some sripting outputting page HTML.

No, other way around.

 I started my code
 ob_start()
 and do an ob_flush() within a function(show_cart) (?might 
 that be a problem?)

Actually, that should be a preventer for the problem, so long as the
ob_start() is executed before output is started -- perhaps your
ob_start() should occur earlier in your script?

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 


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

RE: [PHP] headers already sent and cookie problem

2003-07-16 Thread Ford, Mike [LSS]
 -Original Message-
 From: frederik feys [mailto:[EMAIL PROTECTED]
 Sent: 16 July 2003 10:21
 
 One nasty thing to debug is that the error only shows up from time to
 time.
 So now everything seems OK.
 
 What do i have now?
 I start my code with session_start
 Then include some files. The last one is get_cartID.php (remember?)
 Then i use several functions to have cart functionallity.
 In show_cart i include my page heading and then output 
 further body and
 footer content.
 When I put the get_cartID include file AFTER include 
 heading.php into
 my show cart function, the other functions start complaining 
 they can't
 access the function get_cartID.
 Lots of text, sorry for that. But I still don't have the clue.
 Maybe you like to see my code?

Yes, I think so -- I can't visualize enough of what's going on from your
description to make further suggestions about what you might need to look
at.

From the sound of it, your files are quite big, so the best thing would be
if you can put them up (as .phps or .txt) on your Web server and post their
URLs to the list.  If you can't do that, attach them to an email as .txt
files.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

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



Re: [PHP] headers already sent and cookie problem

2003-07-15 Thread Ryan Gibson
You cannot send any page information before you send headers (ie setting a
cookie), that means there should be no html before the php that sets the
cookie, also any function that are called before you set the cookie cannot
output to the browser.

Ry


On 15/7/03 9:45 am, frederik feys [EMAIL PROTECTED] wrote:

 Hi all,
 
 
 
 This is what i get:
 
 ³Warning: Cannot add header information - headers already sent by (output
 started at /home/u/r/html/store/cart.php:188) in
 /home/u/r/html/store/includes/functions/get_cartID.php on line 14²
 
 
 
 I know that the problem is the reading of the cookie and then after some
 sripting outputting page HTML.
 
 
 
 I started my code
 
 ob_start()
 
 and do an ob_flush() within a function(show_cart) (?might that be a problem?)
 
 
 
 Can anyone shed some light on this?
 
 
 
 Thanks!
 
 Fred
 
 
 
 


Ryan Gibson
---
[EMAIL PROTECTED]


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



RE: [PHP] headers already sent and cookie problem

2003-07-15 Thread Ford, Mike [LSS]
 -Original Message-
 From: frederik feys [mailto:[EMAIL PROTECTED]
 Sent: 15 July 2003 09:45
  
 This is what i get:
 Warning: Cannot add header information - headers already 
 sent by (output started at /home/u/r/html/store/cart.php:188) 
 in /home/u/r/html/store/includes/functions/get_cartID.php on line 14

This says that on line 188 of store/cart.php you started outputting your HTML page, 
but you can't do that before the attempt to send headers on line 14 of 
store/includes/functions/get_cartID.php.  Take a good look at line 188 of 
store/cart.php to see what you can do so that it is not starting HTML output, or move 
the header calls above the point where it is included/required.

 I know that the problem is the reading of the cookie and then 
 after some sripting outputting page HTML.

No, other way around.

 I started my code
 ob_start()
 and do an ob_flush() within a function(show_cart) (?might 
 that be a problem?)

Actually, that should be a preventer for the problem, so long as the ob_start() is 
executed before output is started -- perhaps your ob_start() should occur earlier in 
your script?

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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