2014-05-08 23 views
1

我想贝宝在我的网站整合但之后,我按PayPal按钮会出现这样的错误:用PHP头冲突需要

Warning: Cannot modify header information - headers already sent by (output started at X:\home\test\www\view\main.php:29) in X:\home\test\www\view\frontend\paypalfunctions.php on line 377 

负责错误的main.php的部分是这样的:

<div class="container"> 
     <?php require 'view/frontend/'.$tpl.'.php';?> 
</div> 

这行代码对我整个网站的工作至关重要。它相冲突与PayPal的paypalfunctions.php这个特殊的功能:

function RedirectToPayPal ($token) 
{ 
global $PAYPAL_URL; 

// Redirect to paypal.com here 
$payPalURL = $PAYPAL_URL . $token; 
header("Location: ".$payPalURL); 
exit; 
} 

我仔细看了this question关于这个问题,并尝试了一些东西,但没有找到一个解决方案。有什么我需要改变它的代码工作?

回答

1

ob_start是一种解决方法。我更喜欢解决实际问题。这通常是一个空白问题。

尝试调整以下...

<div class="container"> 
     <?php require 'view/frontend/'.$tpl.'.php';?> 
</div> 

<div class="container"> 
<?php require 'view/frontend/'.$tpl.'.php';?> 
</div> 

看看是否有帮助。还要确保你没有任何额外的空白在包含文件中进行。

2

问题是,您的视图正在输出内容和标题。

的溶液是由ob_start和ob_get_contents缓冲()的输出。 停止查看文件的所有直接输出。 您可能会在需要时输出缓冲区。 在通过头进行PayPal重定向之前,并不需要视图输出。

所以逻辑是:渲染视图缓冲区或做一个头重定向。