$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>hooks - PHP header() gives headers already sent|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

hooks - PHP header() gives headers already sent

matteradmin8PV0评论

I am working on a checkout proces in Wordpress where if customer clicks on the checkout button he gets redirected to a payment provider.

Important to know:

  • I use a session in this proces.
  • I use PHP header() function to sent the customer to this location.

My problem: Now when you click the button, there is no redirect, but an error instead.

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/website/httpdocs/wp-content/themes/template/header.php:24) in /var/www/vhosts/website/httpdocs/wp-content/themes/template/page-checkout.php on line 84

Line 84 is:

header( "Location: " . $payment->getPaymentUrl() );

So it looks like I need to do the redirect earlier, but I don't know how to do it. Has anyone any idea? Hook the init or send_headers action?

I have one solution at the moment which solves the problem, but I know that it is not the right one. The solution is placing ob_start() in the top of my header.php

I am working on a checkout proces in Wordpress where if customer clicks on the checkout button he gets redirected to a payment provider.

Important to know:

  • I use a session in this proces.
  • I use PHP header() function to sent the customer to this location.

My problem: Now when you click the button, there is no redirect, but an error instead.

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/website/httpdocs/wp-content/themes/template/header.php:24) in /var/www/vhosts/website/httpdocs/wp-content/themes/template/page-checkout.php on line 84

Line 84 is:

header( "Location: " . $payment->getPaymentUrl() );

So it looks like I need to do the redirect earlier, but I don't know how to do it. Has anyone any idea? Hook the init or send_headers action?

I have one solution at the moment which solves the problem, but I know that it is not the right one. The solution is placing ob_start() in the top of my header.php

Share Improve this question edited May 20, 2014 at 14:51 Pieter Goosen 55.5k23 gold badges117 silver badges211 bronze badges asked May 20, 2014 at 14:45 RobbertRobbert 1,2756 gold badges23 silver badges47 bronze badges 1
  • Where is your code? Please post it in context. – s_ha_dum Commented May 20, 2014 at 15:10
Add a comment  | 

1 Answer 1

Reset to default 0

I had to do it with WordPress's inbuilt redirect function; wp_redirect();

wp_redirect( $payment->getPaymentUrl() );
exit;

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far