I need help with a cookie please. Need to set a second cookie.

Discussion in 'PHP' started by mikeonthebeach, Sep 3, 2009.

  1. #1
    My web site sets a cookie using the following code:

    
    function alphanumericAndSpace( $string )
        {
    $length = 80;
    return substr (preg_replace('/[^a-zA-Z0-9\s]/', '', $string),0,$length);
        }
    if (isset($_GET['kw']))
      {
      setcookie('keyword', alphanumericAndSpace($_GET['kw']), time()+365*60*24*60);
      }
    if (isset($_COOKIE['keyword']))
      {
      $kw = alphanumericAndSpace($_COOKIE['keyword']);
      }
    
    Code (markup):
    and the result is a cookie "keyword" with a "value"

    I would like to set another cookie "keyword2" with its own "value"


    I would like to keep the 2nd cookie value clean just like the first cookie.

    What code would I have to write to set the second cookie?

    Appreciate your help

    Thanks

    Mike
     
    mikeonthebeach, Sep 3, 2009 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Based on your codes, it would be:

    
    setcookie('keyword2', alphanumericAndSpace($ownvalue), time()+365*60*24*60);
    
    PHP:
    Change the $ownvalue yourself :)
     
    ads2help, Sep 3, 2009 IP
  3. mikeonthebeach

    mikeonthebeach Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the real quick reply.

    Sorry I did not explain that well. What I meant was another value from another variable say "kw2"

    Thanks
     
    mikeonthebeach, Sep 3, 2009 IP
  4. yuvrajm

    yuvrajm Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Simply setcookie another function, with the second cookie name and value of second keyword.

    are you looking for help in getting the second key word?
     
    yuvrajm, Sep 4, 2009 IP
  5. mikeonthebeach

    mikeonthebeach Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for that. Yes I sorted it out this morning. It was easier than I thought. But thanks for getting back on this.

    Mike
     
    mikeonthebeach, Sep 4, 2009 IP