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!
Another way to redirect?
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Another way to redirect?
Couple of things...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!
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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;
}
?>