0

I have this problem being reported in one of my files;

Warning: Cannot modify header information - headers already sent by (output started at /home/*/public_html/addengine/parseclick.php:1) in /home/*/public_html/addengine/parseclick.php on line 40

Here is the code of the actual file;

<?php
 include_once("../admin/database.php");


 $today = date("Y-m-d");

 $data = str_replace(' ', '+', $_GET['data']);
 $de_data = decrypt($data,$ad_passcode='',$salt='');


 $arr_data = explode(":",$de_data);

 /*
 Array: arr_data
 arr_data[0] =  pub_ad_id
 arr_data[1] =  adv_ad_id
 arr_data[2] =  compaign_id
 */

 $pid = $arr_data[0];
 $aid = $arr_data[1];
 $cid = $arr_data[2];

 /*$billing = getvalue("billing_type","compains",$cid);
 if($billing == 'cpc' || $billing == 'both')
 {
countClick($aid,"adds",$pid);
countClick($pid,"pub_adds",$pid);
 }*/

 $adv_ad_id = $aid;
 $pub_ad_id =$pid;
 countClick($adv_ad_id,$pub_ad_id);

 $parenturl =  $_SERVER["HTTP_REFERER"]; 

 if( verifyLegitimateurl($parenturl,$pid) == 'Passed' &&          emailAlreadyExists($_SERVER['REMOTE_ADDR'],"banips","cip") == false)
 {
$url  = getvalue("url","adds",$aid);
header("Location: ".$url);  
    }

    ?>
O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • 3
    http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – tgun926 Feb 01 '14 at 20:52
  • When you post a question, indicate what you want to do, not only the problem you're facing (flagged as **unclear what you're asking**) – Jivan Feb 01 '14 at 20:56
  • Whats your `countClick()` function contents? This might be causing the header warning. – Rahil Wazir Feb 01 '14 at 21:04

3 Answers3

0

The error is because of this line:

header("Location: ".$url); 

You cannot redirect if you already started to write to the page.

So if you have something like this

<!Doctype html>
<?php
header("Location: ".$url); 
?>

You will get that error, you have to make sure you dont have any html above the php , or you dont echo anything.

So if you place your php on top , you wont get the error:

<?php
header("Location: ".$url); 
?>
<!Doctype html>
meda
  • 45,103
  • 14
  • 92
  • 122
-1

instead of

header("Location: ".$url);

use

<META http-equiv="refresh" content="0;URL=<?php echo $url;?>">

obviously you should close the php tag before this html code and start it again after this code

Khan Shahrukh
  • 6,109
  • 4
  • 33
  • 43
-2

Use ob_start(); after <? at the beginning of file and place ob_flush(); before ?> at the end of the file.