using set cookie

This is the place to discuss the LiveCode Hosting service.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
RockyHeuft
Posts: 5
Joined: Thu May 11, 2017 7:19 am

using set cookie

Post by RockyHeuft » Thu Sep 17, 2020 5:51 am

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

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: using set cookie

Post by bangkok » Thu Sep 17, 2020 4:22 pm

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>

RockyHeuft
Posts: 5
Joined: Thu May 11, 2017 7:19 am

Re: using set cookie

Post by RockyHeuft » Fri Sep 18, 2020 5:44 am

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

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: using set cookie

Post by bangkok » Fri Sep 18, 2020 10:20 am

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.

RockyHeuft
Posts: 5
Joined: Thu May 11, 2017 7:19 am

Re: using set cookie

Post by RockyHeuft » Sat Sep 19, 2020 5:13 pm

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

Post Reply

Return to “LiveCode Hosting”