...

View Full Version : Help echoing cookie



SDP2006
11-12-2003, 10:01 PM
My script sets a cookie with a users name so when they come back, they will see "Welcome back, John!" or what not.

<?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
if(isset($_COOKIE['username'])){
$linked = "Welcome back,. $_COOKIE['username'].";
}else{
$linked = "Find out how to personalize our site!";
}
echo $linked
?>

My error is

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 53Does anyone see my problem? Thanks

Michiel
11-12-2003, 10:55 PM
Hi,

try this:



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


?>

Nightfire
11-12-2003, 11:39 PM
You got the ." in the wrong place



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

SDP2006
11-13-2003, 01:36 AM
Thanks....:thumbsup:

ReadMe.txt
11-16-2003, 01:18 PM
you can also just wrap your cookie var in curly braces:


echo "Welcome back, {$_COOKIE['username']}.";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum