header('location: foo.php');

is not working for me. the page that is supposed to redirect just dies. no error, no redirect, no nothing.

this is the code in my main file:

if ($payment_required == 0) {
$log->write('NO PAYMENT REQUIRED, REDIRECTING TO post_thanks.php');
  jta_redirect('post_thanks.php');
} else {
  // do shopping cart addition code and link out to paypal
die('extra ' . $payment_required . ' worth of features requested...handle it');
}

here is the function jta_redirect():

function jta_redirect($url) {
  global $session;
  global $log;
	$file = '';
	$line = '';
  if (headers_sent($file, $line)) {
    die('Unable to redirect.  headers already sent in file ' . $file . ' on line ' . $line . '.');
  }
$log->write(' headers:' . headers_sent());
  $url = $session->add_sid($url);
$log->write('attempting redirect, url:' . $url);
  header('location: ' . $url);
	exit();
} // jta_redirect()

this is what results in the log:

NO PAYMENT REQUIRED, REDIRECTING TO post_thanks.php
attempting redirect, headers:
attempting redirect, url:post_thanks.php

What might be the story here? What might cause a header() redirect no to work? it works most of the time, but if the browser window has remained open for a few minutes, it often doesn't work.

    Are you logging PHP errors as well or are they just shown in your browser (display_errors = On in php.ini)?

    Are you sure there is no output before the header('location') callA?

      I suspect mjax is right--have you posted up the whole main file or just the snippet that is causing the problem? redirect has to be performed before there is any html output. I was banging my head against that a while back......

        i have written my own error handling routines which complicates the matter, but i also have a log output whenever the error handler gets called...it is getting called for some notices/warnings (such as undefined array keys being referenced) but NONE of these errors outputs any text. all error echoing is off.

          Write a Reply...