Jump to content

a very simple php header question (sorry!)


carleyvibe

Recommended Posts

Firstly...I do apologise if this annoys anyone....a header error

 

I'm do not know php & have tried removing all "white space" but I cant seem to stop the error displaying.

 

Its a very simple PayPal buy it now button with an affiliate link (using this product: www.idevspot.com/PhpAffiliate.php )

 

http://fuselovesit.co.uk/tickets2.php - displays OK

http://fuselovesit.co.uk/tickets2.php?xyz=4 - displays error below

Warning: Cannot modify header information - headers already sent by (output started at /home/fuselove/public_html/tickets2.php:3) in /home/fuselove/public_html/affiliate/tracker/tracker.php on line 22

 

Originally I was working through a wordpress site & thought the error was something to do with that...but I've even tried a very simple page & still get the errors :(

 

I'd greatly appreciate if someone could help me

 

Regards

Carley

Link to comment
https://forums.phpfreaks.com/topic/177896-a-very-simple-php-header-question-sorry/
Share on other sites

Line 3 in the /home/fuselove/public_html/tickets2.php script is echoing something to the browser before your headers statement at line 22 in /home/fuselove/public_html/affiliate/tracker/tracker.php, so what are the lines immediately around line 3 of tickets2.php?

I dont get it :(

 

....the lines around line 3 are <head> tags...

 

...line 22 is " setcookie ("phpaffiliateid", $affid, time()+60*60*24*30);

(I think!)

 

thanks!

 

 

<html>
<head>
<?php include "/home/fuselove/public_html/affiliate/tracker/tracker.php" ; ?>
</head>
<body>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="8852384">
<input type="image" src="https://www.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1"></p><input type="hidden" name="notify_url" value ="http://www.fuselovesit.co.uk/affiliate/ipn.php?xyz=<?php echo $affid; ?>"></form>
</body>
</html>

 

<?PHP
include "/home/fuselove/public_html/affiliate/include/mysql.php";

if (!is_numeric($_GET[xyz]) && $_GET[xyz] != $nil) die("mmm... no");

$affid = htmlentities($_GET[xyz], ENT_QUOTES);


if (empty($HTTP_COOKIE_VARS[phpaffiliateid]) && !empty($affid)) {
        $sql = "INSERT INTO REFTRACK SET AFFID = '$_GET[xyz]'"; $query = mysql_query($sql);
}

$SQL = "SELECT * from REFTRACK WHERE AFFID = '$affid'"; 
$result = @mysql_query( $SQL ); $row = @mysql_fetch_array( $result );

if ($row[AFFID] != $affid && !empty($affid) && $affid != $HTTP_COOKIE_VARS[phpaffiliateid]) {
        $sql = "INSERT INTO REFTRACK SET AFFID = '$affid'"; $query = mysql_query($sql);
	setcookie ("phpaffiliateid", $affid, time()+60*60*24*30);
}

if (empty($HTTP_COOKIE_VARS[phpaffiliateid]) && !empty($affid)) 
setcookie ("phpaffiliateid", $affid, time()+60*60*24*30);

if (!empty($affid) && !empty($HTTP_COOKIE_VARS[phpaffiliateid]) && $HTTP_COOKIE_VARS[phpaffiliateid] != $affid)
	setcookie ("phpaffiliateid", $affid, time()+60*60*24*30);

if (empty($HTTP_COOKIE_VARS[phpaffiliateid]))
        $affid = $affid;
else
        $affid = $HTTP_COOKIE_VARS[phpaffiliateid];
?>

....the lines around line 3 are <head> tags...

 

...line 22 is " setcookie ("phpaffiliateid", $affid, time()+60*60*24*30);

OK, put simply <head> is an html markup tag that is sent as output that is sent to the browser.

It is not to be confused the "headers", which are a series of instructions sent to the browser before any of the html. Cookies are sent as part of the "headers"

Once the first character of html markup is sent, then "headers" can not be sent

 

tickets2.php is sending html markup, so once it has started to send that output, any attempt to send "headers" will generate an error. After tickets2.php has sent that markup, then line 22 of tracker.php tries to set a cookie (which is part of the "headers"). It can't because of tickets2.php

 

The solution is generally to reorganise your code so that all "headers" are sent before any html markup.

As an alternative, output buffering (well documented on php.net) allows you to delay sending the html markup until the very end of your script.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.