SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm having a hell of a trubble with this. There does not seem to be much in the way of PHP cookie examples around, so I must be missing somethin very basic. Here's the code...

    This gets form input in the form of two arrays, stick 'em together, then sets the cookie...

    <?php
    $stock_string = implode (",",$stock_choice);
    $feed_cookie = implode (",",$feed_choice);
    $feed_cookie = $feed_cookie . "," . $stock_string;
    setcookie("feed_cookie", $feed_cookie, time() + 3600);
    ?>

    This is a section of code I would like to read the cookie, it reads the cookie in, then breaks a few chunks off the end....

    $HTTP_COOKIE_VARS["feed_cookie"];
    if (strlen($feed_cookie) == 0) {
    $cookie_stat = 0;
    } else {
    $cookie_stat = 1;
    $stocks = substr (strrchr ($feed_cookie, ","), 1);
    $feed_cookie = substr ($feed_cookie, 0, (strlen ($feed_cookie) - strlen($stocks)));
    $stocks2 = substr (strrchr ($feed_cookie, ","), 1);
    $feed_cookie = substr ($feed_cookie, 0, (strlen ($feed_cookie) - strlen($stocks2)));
    $stocks3 = substr (strrchr ($feed_cookie, ","), 1);
    $feed_cookie = substr ($feed_cookie, 0, (strlen ($feed_cookie) - strlen($stocks3)));
    }

    But, alas, it does nothing because it cant see the cookie(?).

    What am I missing?


    [This message has been edited by jake (edited July 08, 2000).]

    [This message has been edited by jake (edited July 08, 2000).]

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is your problem.

    $HTTP_COOKIE_VARS["feed_cookie"];

    You are essentially trying to execute the function named by feed_cookie. Say feed_cookie had the contents of 'hi_all' then you'd be executing the function hi_all().

    Assuming that you haven't done anything radically different with your php.ini file, simply delete the line I highlighted above. PHP automatically assigns $feed_cookie to $HTTP_COOKIE_VARS['feed_cookie']. That's why I love the language


  3. #3
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, correction. You aren't executing any function by any name. Why it didn't return an error message is beyond me...

  4. #4
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what I wonder is what the intent of
    $HTTP_COOKIE_VARS["feed_cookie"]; is

    firstly,

    $feed_cookie = $HTTP_COOKIE_VARS["feed_cookie"];

    would be better.. you are essentially wiping $feed_cookie out on the top when its trying to set the cookie...

    perhaps do this on the top

    if($HTTP_COOKIE_VARS["feed_cookie"] != "")
    {
    set the cookie here
    }

    hmmmm. maybe i'm just confused

    ---------------------
    my PHP host


Bookmarks

Posting Permissions

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