#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    This below is my simple source to set a cookie:


    <?
    setcookie('geinig', 'banaan');
    ?>

    Though it doesn't set the cookie, can't find it in my directory cookies, below is an advanced example I pulled from devshed:

    <?

    // set cookie if not already set

    if (!isset($id)) {
    srand((double)microtime()*1000000);
    $randval = rand();
    setcookie("id",$randval,1003842401,"/","localhost",0);
    }

    setcookie("id",$randval,1003842401,"/","localhost",0);

    // a cookie to expire for 4 hours -> time()+14400


    ?>

    But I can't get any values, perhaps because the cookie isn't set.

    Used the below code to get the code: (used various codes though)

    <? echo $HTTP_COOKIE_VARS["id"]; ?>

    Any help would be much appreciated!

    Hans



    ------------------
    ---------------------
    Hans Buis
    Framers
    http://www.framers.nl
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    29
    Rep Power
    0
    You are forgetting to assign time, it is probably expiring before you get to pull it out, do something like: setcookie('geinig', 'banaan', time()+100000);

    That should give you plenty of time to see if the cookie worked, also if that doesn't work, turn on Cookie notification in your browser, that way you can tell if iti s actually sending the cookie or not.

    Vlad
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    Nopes, doesn't work. Get this error:

    Warning: Cannot add header information - headers already sent by (output started at chpweb/practise/cookies/setcookie_2.php:4) in chpweb/practise/cookies/setcookie_2.php on line 6

    I don't need to use sessions or what so ever right? Perhaps I'm missing something here.

    Hans

    ------------------
    ---------------------
    Hans Buis
    Framers
    http://www.framers.nl
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Melbourne, Victoria, Australia
    Posts
    104
    Rep Power
    14
    You must do the setcookie() before you make any output... eg print() echo() printf() Header() etc

Similar Threads

  1. Apache 2 and PHP 4
    By stanley1610 in forum Apache Development
    Replies: 2
    Last Post: February 12th, 2004, 08:20 PM
  2. php for apache
    By wannabe in forum Beginner Programming
    Replies: 3
    Last Post: February 6th, 2004, 02:28 PM
  3. PHP -> system commands
    By Tantalus in forum PHP Development
    Replies: 1
    Last Post: January 28th, 2004, 10:51 AM
  4. Can PHP interpret Apache Directory Protection?
    By xpatriot in forum PHP Development
    Replies: 1
    Last Post: January 25th, 2004, 01:51 PM
  5. UnixODBC + PHP + Apache + Empress
    By coder4hire in forum Database Management
    Replies: 0
    Last Post: January 15th, 2004, 01:41 PM

IMN logo majestic logo threadwatch logo seochat tools logo