Jump to content

Cookie Tutorial


niche

Recommended Posts

I found this in the cookie tutorial and it didn't work for me:<?phpif (isset($_COOKIE["user"])) echo "Welcome " . $_COOKIE["user"] . "!<br />";else echo "Welcome guest!<br />";?>I changed it to something that I thought would work, but I still get the error:Parse error: parse error in C:\wamp\www\temp109.php on line 3<?phpif (isset($_COOKIE['user'])) { echo "Welcome " . $_COOKIE['user'] . '<br />';}else { echo "Welcome guest!". '<br />';} ?>Why?PS <?PHP echo $_COOKIE['user']; ?> works for me

Link to comment
Share on other sites

Nothing's wrong with either script. I would usually use quotes and brackets differently, but it worked nonetheless. I tested both versions of the script, and both worked. Are you including other files, or is this the entire file?

Link to comment
Share on other sites

Now, it works for me too. Don't know what the problem was. Anyway, what's with no curly brackets? I thought they were required in an if statement.Also, what !<br/> mean? I haven't seen that before.

Link to comment
Share on other sites

Now, it works for me too. Don't know what the problem was. Anyway, what's with no curly brackets? I thought they were required in an if statement.Also, what !<br/> mean? I haven't seen that before.
i cant remember exactly but i saw in book like that if else..where curly bracet was not using..as far i can remember it is for short hand php. though i dont use that. i am comfortable with the bracets. as far i can remember is short hand it was writing like..
if(isset($_COOKIE['something']): // it is existelse: //it doesnt exist

<br/> is simply line break code from html

Link to comment
Share on other sites

Anyway, what's with no curly brackets? I thought they were required in an if statement.
It's just a shorthand. It's perfectly legal, however, I think it's only legal if an if/else will only have one statement per blockie, this is legal:
if (...condition...)   //do somethingelse   //do something else

This is not:

if (...condition...)   //do something   //do some more stuffelse   //do something else   //do some more stuff

Also, what !<br/> mean? I haven't seen that before.
Like Synook said, it's just part of the string that will be echoed.
Link to comment
Share on other sites

Now, it works for me too. Don't know what the problem was. Anyway, what's with no curly brackets? I thought they were required in an if statement.Also, what !<br/> mean? I haven't seen that before.
its part of the output, Welcome [user]!
Link to comment
Share on other sites

Oh wow. I wish I had an excuse for that last one post of mine!You all are top-notch as usual. Thanks to Fmdpa, birbal, Synook, ShadowMage, and thescientist.Niche

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...