Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts

    errors in cookie script

    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 ;
    ?>

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •