Page 1 of 1
Another way to redirect?
Posted: Thu Jun 15, 2006 1:13 pm
by Milan
I have a line
header("Location: ". "../buyer4d.php?result=canceled&session=".$_GET['session']);
to return the buyer to the original page is he canceled his order but when paypal tries to return to it it gives me error:
Warning: Cannot modify header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\pickageek\secrfld\paypal.class.php:2) in c:\program files\apache group\apache\htdocs\pickageek\secrfld\annpaypal.php on line 60
is there another way to redirect? or trace the problem in this code?
thanks!
Posted: Thu Jun 15, 2006 1:22 pm
by TheMoose
You could always have a 'redirecting' page, that does all the processing and whatnot, and then once done, just writes out a meta-refresh tag to the page you want to return to. Like the typical "Thank you, redirecting in 5 seconds", type thing.
Re: Another way to redirect?
Posted: Thu Jun 15, 2006 1:39 pm
by RobertGonzalez
Milan wrote:I have a line
header("Location: ". "../buyer4d.php?result=canceled&session=".$_GET['session']);
to return the buyer to the original page is he canceled his order but when paypal tries to return to it it gives me error:
Warning: Cannot modify header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\pickageek\secrfld\paypal.class.php:2) in c:\program files\apache group\apache\htdocs\pickageek\secrfld\annpaypal.php on line 60
is there another way to redirect? or trace the problem in this code?
thanks!
Couple of things...
1) Use full URL's using the header() function.
2) The error you are getting is because there was output sent to the browser already. Make sure there is nothing sent to the browser before calling header().
3) You can always use meta redirection in your HTML or a JavaScript redirect if you want. I usually use meta redirection as a fallback to servers that may not support the header() redirect.
Posted: Thu Jun 15, 2006 2:47 pm
by Weirdan
servers that may not support the header() redirect
Have you encountered any?

Posted: Thu Jun 15, 2006 3:24 pm
by RobertGonzalez
I borrowed this snippet from the phpBB codebase. I have never put PHP code on a WebSTAR or Xitami server. Not sure about Microsoft.
Code: Select all
<?php
// Redirect via an HTML form for PITA webservers
function redirect($url)
{
if (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')))
{
header('Refresh: 0; URL=http://www.mysite.com/'. $url);
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=http://www.mysite.com/' . $url . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="http://www.mysite.com/' . $url . '">HERE</a> to be redirected</div></body></html>';
exit;
}
// Behave as per HTTP/1.1 spec for others
header('Location: http://www.mysite.com/' . $url);
exit;
}
?>