Forum Moderators: coopster
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/production/wishlist.php:5) in /var/www/html/production/wishlist.php on line 9
The offending code fragment is as follows:
<?php
require_once( "./config/config.inc.php" );
if(! $nb[ 'user' ]->LoggedIn()) {
if($add) {
$redirect .= 'add=' . $add . '&';
}
session_register("redirect");
header( "Location: ".$nb[ 'redirect' ]."login.php" );
exit();
}
...
I know that this sort of error is often caused by whitespace before leading '<?php' or after trailing '?>'. I checked out all the PHP files involved, all of them are fine. Besides, as I said, the code works on the older box. Actually, this is just an example. There are more errors like this where redirection is requested. What can be wrong?
Thanks in advance.
69.26.213.178 - - [22/Jul/2005:20:37:03 -0500] "POST /checkout.php HTTP/1.1" 200 15966
69.26.213.178 - - [22/Jul/2005:20:37:11 -0500] "POST /checkout.php HTTP/1.1" 302 -
69.26.213.178 - - [22/Jul/2005:20:37:11 -0500] "GET /checkout2.php?cartnumber=050722000047 HTTP/1.1" 302 -
69.26.213.178 - - [22/Jul/2005:20:37:11 -0500] "GET /checkout.php?cartnumber=050722000047 HTTP/1.1" 200 16276
checkout2.php is where I should get. checkout.php is what I am being thrown back into.
This is how the first few lines of code look:
<?php
require_once( "./config/config.inc.php" );
if( $nb[ 'user' ]->LoggedIn() ) {
if( $nb[ 'cart' ]->UserID() == "0" ) { // added to fix userid=0/status=pending issue in newcarts
$nb[ 'cart' ]->EditField( "userid", $nb[ 'user' ]->UserID() );
}
//header( "Location: ".$nb[ 'redirect' ]."checkout2.php" );
// set cartnumber in the URL for temp fix to Safari problem
$cartnumber = !empty( $nb[ 'cart' ]->cartid )? $nb[ 'cart' ]->cartid : session_id();
header( "Location: [".$nb[...] "thisserver" ]."/checkout2.php?cartnumber=" . $cartnumber );
exit();
}
I would greatly appreciate your advice.
The require_once file path or name could be wrong.
The '$nb' class may not exist.
The variables, '$add' and '$redirect', may be undefined. You should always use this: [i]if(isset($add) && $add){...
Any error or notice will cause the header() call to exit the script. You should see another error though.
Question: Are there any other errors showing?
Regards,
Marty
[added]opps! Took a long time to write that post. You already shot my theory down. Oh well, I'll leave it up anyhow.[/added]
[added2]Sorry erg, you asked the same q too :o[/added2]
There are usually some warning about undefined variables (I am running Apache in the debug mode), but no errors.
Same difference. Those count as output and you can't send headers after output. If it shows on the browser, it's output.
I suspect that what is different from one machine to the other is something like error reporting (now showing notices, but previously didn't) or register_globals is off (so was always showing notices, but was not flagging the variables as undefined).
Get rid of all notices, warnings and errors and then see what's happening
First, pick a file (wishlist.php) and turn up eror_reporting:
<?php
eror_reporting(E_ALL);
require_once( "./config/config.inc.php" );
...
Then, browse to that page and look for probs. Hopefully, that will turn something up.
[added]dang I'm slow today! i'm goin for a beer :)[/added]
I've seen so many logic errors that creep in b/c people turn error_reporting down during development. PHP is simply too permissive in its default state.