Page 1 of 1

using set cookie

Posted: Thu Sep 17, 2020 5:51 am
by RockyHeuft
Hello all,

I would like to use a cookie in my web design. I have located the put cookie command in the LiveCode dictionary. I understand the syntax but I am having trouble figuring out where to place the put cookie command in my .lc file.

The documentation says that the command has to be prior to any header command. I have placed my command just after the <html> tag with no success.

<html>
<head>
<title>
my little slice of heaven
</title>
</head>
<body>
</body>
</html>

Can anyone share a few lines of code showing the proper context for put cookie usage.

Regards, Rocky Heuft

Re: using set cookie

Posted: Thu Sep 17, 2020 4:22 pm
by bangkok
You need to use cookies functions before... anything else.
;-)

At the top of your .lc file.

Example :

Code: Select all

<?lc
set the errorMode to "inline"

put $_COOKIE into tCookie
put tCookie["myCookie1"]  into tCookie

if tCookie is empty then
put new header "Location: index.lc?C=1"
put "Sorry..."
quit
end if

put char 1 to 2 of $_SERVER["HTTP_ACCEPT_LANGUAGE"] into tLanguage

put $_POST["email"] into tEmail

include "../includes/fonctions.lc"

?>
<html>
<head>
<title>
my little slice of heaven
</title>
</head>
<body>
</body>
</html>

Re: using set cookie

Posted: Fri Sep 18, 2020 5:44 am
by RockyHeuft
Hello and thank you.

I have tried to put my Cookie coding at the top of my file with no luck.

I do not have an ../includes/ folder on my system. Is that part of some extra install process?

Regards, Rocky Heuft

Re: using set cookie

Posted: Fri Sep 18, 2020 10:20 am
by bangkok
RockyHeuft wrote:
Fri Sep 18, 2020 5:44 am
I have tried to put my Cookie coding at the top of my file with no luck.
I do not have an ../includes/ folder on my system. Is that part of some extra install process?
No it was just to show you what can be done.

So, I guess your problem comes from the script that writes/creates the cookie.

You need to check this. What is your script ?

One tip : create 2 news lc files. With simple content inside.

the first one : where you create the cookie (it will act like your "index" page, where your user arrives when he connects to your site)

the second one : where you read the cookie (and perform some verifications)

And then play with those 2 files, to see the interactions.

Re: using set cookie

Posted: Sat Sep 19, 2020 5:13 pm
by RockyHeuft
Hello and good day.

I tried it again with a very simple page. I now can get set cookie to work properly.

Thank you for your help.

Regards, Rocky Heuft