...

View Full Version : errors in cookie script



lse123
02-09-2006, 10:00 AM
I write the code below but I try to run the webpage but errors appear ... ? Where is the problem ? ...try webpage below:
http://paphoscarhire.com/index09feb2006.php?aff=99998
-------------------------------------------------------------
<?php
session_start( );
$affiliate = '10000'; //default value
if (isset($_COOKIE['aff']) && ($_COOKIE['aff'] != Null))
{
$affiliate = $_COOKIE['aff'];
}
else if (isset($_GET['aff']) && ($_GET['aff'] != Null)) {
$affiliate = $_GET['aff'];
setcookie("aff", $affiliate, time()+60*60*24*90); // 3 months
}
$_SESSION['affiliate'] = $affiliate ;
?>

degsy
02-09-2006, 04:12 PM
setcookie("aff", $affiliate, time()+60*60*24*90); // 3 months

Anything like this has to be done before any output.This means echo, print or HTML.

Make sure the code is at the top of your script.
There is a way around it using ob_flush, but it is not good practice.

http://uk2.php.net/ob_flush


Nice place Pathos. I was there in the summer :cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum