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 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help echoing cookie

    My script sets a cookie with a users name so when they come back, they will see "Welcome back, John!" or what not.
    PHP Code:
    <?php
    $name 
    $_POST['name'];
    if(isset(
    $name)){
    setcookie("username",$name,time()+31536000);
    echo 
    "Thanks!<br>";
    echo 
    "<a href=\"entry.php?cat=home\">Return Home</a>";
    exit;
    }
    else{
    echo 
    "You didn't enter a name for yourself!";
    }
    ?>
    That works fine. And then I echo the cookie, where my problem is
    PHP Code:
    <?php
    if(isset($_COOKIE['username'])){
      
    $linked "Welcome back,. $_COOKIE['username'].";
    }else{
      
    $linked "Find out how to personalize our site!";
    }
    echo 
    $linked
    ?>
    My error is
    Code:
    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/entry.php on line 53
    Does anyone see my problem? Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    try this:

    PHP Code:
    if(isset($_COOKIE['username'])){
      
    $linked "Welcome back, "$_COOKIE['username'];
    }else{
      
    $linked "Find out how to personalize our site!";
    }
    echo 
    $linked 
    Haven't tested is, but I think it will work now.

    Cheers, Michiel


    ?>

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You got the ." in the wrong place

    PHP Code:
    <?php
    if(isset($_COOKIE['username'])){
      
    $linked "Welcome back, "$_COOKIE['username'];
    }else{
      
    $linked "Find out how to personalize our site!";
    }
    echo 
    $linked
    ?>

  • #4
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks....
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can also just wrap your cookie var in curly braces:

    PHP Code:
    echo "Welcome back, {$_COOKIE['username']}."
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)


  •  

    Posting Permissions

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