dongsu0308 2014-05-20 14:43
浏览 24

Wordpress PHP header()提供已发送的标题[重复]

This question already has an answer here:

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.com/httpdocs/wp-content/themes/template/header.php:24) in /var/www/vhosts/website.com/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

</div>
  • 写回答

2条回答 默认 最新

  • dongshou6788 2014-05-20 14:50
    关注

    headers are only sent before echoing any data, so use it before any echo, printf, etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分