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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookie issue - help requested

    I'm able to set a cookie but unable to read the value later on; here is the code ..

    Page 1: This code checks if a cookie named tipsare is present. If so, it collects the value and $tipsarens get that value. Later, a textbox will have that value of $tipsarens.

    PHP Code:
    <? 
    if (isset($_COOKIE['tipsare']))
        {
            
    $tipsarens $_COOKIE['tipsare'];
        }
    else
        {
            
    $tipsarens "No cookie saved (to check if the cookie is there)";
        }
    ?>
    Page 2: This code takes the value from a textbox (thus $_POST) and if no cookie named tipsare is present, it will create one and add a value to it from $_POST['vemskrev'].

    PHP Code:
    <?
    $tipsnamn 
    $_POST['vemskrev'];
    if (!isset(
    $_COOKIE['tipsare'])) 
        {
            
    setcookie('tipsare''$tipsnamn'time() + 2592000);
        }
    ?>
    Now, I can't get the code to work. It shows the value $tipsnamn instead of the wanted value. How can I this to work. All help is appreciated. $_POST['vemskrev'] is the value from a textbox.

    // Daniel

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    setcookie('tipsare', $tipsnamn, time() + 2592000);

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That was embarrasing to the max. Thanks for pointing out that simple error.


  •  

    Posting Permissions

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