A biscuit and a cup of tea (things from the past) (='.'=)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

A biscuit and a cup of tea (things from the past) (='.'=)

Post by Mariasole » Tue Mar 14, 2017 5:35 pm

Hello everyone!
I would like to ask you something about the biscuits, or... the cookies :shock:
How do I create a cookie with a date in the past with LCS?

In fact, I'm trying to do what I was advised: "To delete a cookie, you can overwrite it with an expiry date in the past". :oops:
Obviously I can not. :cry:

I read the lesson well, but I do not find the solution. [http://lessons.livecode.com/m/4070/l/40 ... ode-server].

If there was someone with a good heart who can help me I would be really happy.

Thanks again to put me up in this forum. I am an eternal beginner! Excuse me!

Mariasole
(='.'=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by FourthWorld » Tue Mar 14, 2017 7:19 pm

That Lesson seems to cover that. What happened when you tried it?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by Mariasole » Tue Mar 14, 2017 7:36 pm

Hi Richard!

I do not understand the syntax to use.

why ...(the seconds + 60 * 60 * 24 * 365) it works and ....(the seconds - 60 * 60 * 24 * 365) does not work?

And how can I write:
... until ("Thu, 01-Jan-1970 00:00:01 GMT")

I did a lot of testing, but can not find an example of syntax.
(for long time I try and try again!)

Thank you for your help!

Mariasole
(=^‥^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by SparkOut » Tue Mar 14, 2017 8:22 pm

Cara Maria

Firstly can you tell whether the cookie is being set at all? You must set the cookie BEFORE any output headers are sent from the server (so before the <html> declaration, right at the top of your livecode file

The cookie expiry time is measured in seconds from the start of the Unix epoch (1st Jan 1970 at 00:00 UTC)

"the seconds" is the current time in seconds since the start of the epoch, so setting the expiry to "(the seconds + 60 * 60 * 24 * 365)" will add 1 years worth of seconds to the current time and set that, so as to expire in the future. You don't need to format the time, just set the expiry time in seconds. So if you want to backdate your expiry time to unset the cookie, you can use any number that is less than the current seconds, eg 1 or "the seconds -1" such as

Code: Select all

put cookie "mycookie" for "/" with "The data" until 1
I hope this helps :)

(Incidentally,

Code: Select all

put cookie "yearcookie" for "/" with "This cookie will expire now" until (the seconds - 60 * 60 * 24 * 365)
works just fine to set the expiry back in the past by 1 year for me on my on-rev server)

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by Mariasole » Wed Mar 15, 2017 3:25 pm

Carissimo e gentilissimo SparkOut,
probably I'm completely inept! :oops:

These are the three examples.

Code: Select all

<?lc
///// TRY YOURSELF :) 
// example 1
--put cookie "mycookie" for "/" with "1st Jan 1970 at 00:00 GMT" until 1
// example 2
--put cookie "mycookie" for "/" with "OK" until (the seconds - 60 * 60 * 24 * 365)
// example 3 [classic mode]
--put cookie "mycookie" for "/" with "OK" until (the seconds + 60 * 60 * 24 * 365)
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SAMPLE COOKIES</title>
</head>

<body>
hello
</body>
</html>
To me it only works on the third!
[server: Livecode | OS: Linux | Engine: 8.1.2 ]

Moral of the story: I can not write a cookie to the past!
Where am I wrong?

Grazie dolcissimo SparkOut, and thanks in advance to all for your valuable help!


Mariasole
(=^‥^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by [-hh] » Wed Mar 15, 2017 6:13 pm

MariaSole,
because you ask this every 5 months and SparkOut is seldom wrong I looked into the web server mechanism for cookies. If LCServer accepts his settings but it doesn't work at the very end then probably the webserver changes it back:

The web server has 'the last word' regarding cookies. LCServer just sends your request to the web server 'on top of' it, which runs LCServer. Most web servers, for example Apache, have the following cookie-expiration-scheme:
  • (a) If you set the expiration date to 0 (zero)** then the cookie is deleted when the browser is closed. This is the default.
  • (b) Else if you set the expiration date to a value in the past then the cookie is deleted.
So, if LCServer sends an expiration date in the past that is not zero to the web server, then the web server will immediately delete (or ignore) the cookie for the path (= "/" in your case), item (b) applies.
mariasole wrote:And how can I write:
... until ("Thu, 01-Jan-1970 00:00:01 GMT")
**This is the base of the unix-date-seconds, so it's the same as put cookie "mycookie" for "/" with "The data" until 0.

In case you mean how to convert seconds to such a time display: 'Carissimo e gentilissimo SparkOut' is an expert for that ;-)
shiftLock happens

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by Mariasole » Wed Mar 15, 2017 6:59 pm

Carissimo e gentilissimo Hermann,
anzi dovrei dire squisitamente gentile Hermann :wink:

Did you see how I'm constant?
Months and months to be able to solve a problem! 8)
But I still can not ... :shock:
Thanks for letting me finally explained how it works LCS Cookies Management System! :D
But the problem remains one ... :(
How can I write a cookie in the past?
Or maybe it's just not possible?

Grazie ancora Hermann, you are a true gentleman... :mrgreen:

Mariasole
(=^‥^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by SparkOut » Wed Mar 15, 2017 8:59 pm

Cara Maria,

I can only guess that the Linux version of LiveCode Server 8.12 is glitching, or else your hosting environment is causing some other problem.

Can you try installing a more recent version of LiveCode Server?

I have set up the following page on my server:

Code: Select all

<?lc
///// TRY YOURSELF :) 
// example 1
put cookie "mycookie" for "/" with "1st Jan 1970 at 00:00 GMT" until 1
// example 2
put cookie "mycookie2" for "/" with "OK" until (the seconds - 60 * 60 * 24 * 365)
// example 3 [classic mode]
put cookie "mycookie3" for "/" with "OK" until (the seconds + 60 * 60 * 24 * 365)
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SAMPLE COOKIES</title>
</head>
<body>
Buona sera, cara Maria<br />
<?lc
// Commands to display an array in readable form
command printArray pArrayName, pArray
	if pArray is an array then
	put pArrayname & " = {" & "<br />"
	dumpArray pArray, " ", " "
	put "}"
	end if
end printArray

command dumpArray pArray, pIndent, pIndentString
	local tKeys
	if pArray is an array then
	   put the keys of pArray into tKeys
       sort lines of tKeys
	   repeat for each line tKey in tKeys
	      if pArray[tKey] is an array then
		     put pIndent & tKey & " = {" & "<br />" & return
			 dumpArray pArray[tKey], (pIndent & pIndentString), pIndentString
			 put pIndent & "}" & "<br />" & return
		  else
		     put pIndent & tKey & " = " & pArray[tKey] & "<br />" & return
		  end if
	   end repeat
	end if
end dumpArray
?>
<?lc
// Output cookies
put "PRINTING COOKIES:" & "<br /><br />"
put $_COOKIE into tCookiesArray
if tCookiesArray is an array then
	printArray "$_COOKIE", tCookiesArray
else
	put "no cookies found"
end if
put "<br /><br />" & "FINISHED"
?>
</body>
</html>
The response headers clearly show the correct cookie setting for all the cookies:

Code: Select all

Set-Cookie: mycookie=1st+Jan+1970+at+00%3A00+GMT; Expires=Wed, 31 Dec 1969 19:00:01 -0500; Path=; Domain=
Set-Cookie: mycookie2=OK; Expires=Tue, 15 Mar 2016 15:49:22 -0400; Path=; Domain=
Set-Cookie: mycookie3=OK; Expires=Thu, 15 Mar 2018 15:49:22 -0400; Path=; Domain=
The page displayed shows:

Code: Select all

Buona sera, cara Maria
PRINTING COOKIES:

$_COOKIE = {
mycookie3 = OK
}

FINISHED 
Cookies mycookie and mycookie2 are set in the past, so the printout of the cookies read by the server script for output only shows mycookie3. It's all working well for me. Your scripting is not at fault, there must be something else that is the problem.
hmm.....

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by [-hh] » Wed Mar 15, 2017 9:02 pm

Mariasole,

I wasn't clear enough: You can NOT set the expiration date to a date in the past. If you do that,
then the webserver (which has LCServer as helper) will take this as an order to delete that cookie.

The people who decided to choose this mechanism for deleting a cookie couldn't see any sense in setting an already expired cookie.

What would you like to achieve by setting an already expired cookie?
Perhaps we can find another way to get to there. Many roads lead to Rome.
shiftLock happens

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by Mariasole » Fri Mar 17, 2017 7:22 pm

Thank you so much for your help carissimi e gentilissimi SparkOut and Hermann! :D

Thanks SparkOut because by your script I understood what he meant Hermann!

I had not seen since the "physically" cookie in the Firefox cache, I thought that simply LCS not write it! :lol:
Instead LCS writes all 3 cookies, but the web server deletes it (true Hermann?). :roll:
In fact I see only one cookie in Firefox (the one with the "contemporary" data) while other "invisible" (those with the date in the past) I can track them on the "response headers". :?
I did not know that there was even this "header" (I downloaded a firefox plugin to see it). :o

Then SparkOut script's works perfectly! :D
I'm the one who did not work perfectly, or rather, I am too ignorant! :shock:

That said, let's get to what I want to do for months! 8)

a) the page A places a cookie "meow" that has an expiration time of one year
b) the user navigates in the page A, B, C, D, E, F and always has this cookie "meow" has an expiration time of one year
c) when the user happens in the Z page the cookie "meow" is deleted, no longer exists! I thought I could send the date of the cookie "meow" in the past (at least so I read in PHP, but I do not understand it) to do this.


Is there any other road leading to Rome? :wink:

Grazie davvero a tutti!
Miao! (meow ---> miao in italian)

Mariasole
(=^‥^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by SparkOut » Fri Mar 17, 2017 7:30 pm

Cara Maria,
What you have written is (nearly) exactly what happens with the test scripts you have already got above.
It is not the web server that deletes the cookie - it sets the expiry time in the past.
The web BROWSER then will not send an expired cookie to the server any more - this is equivalent to deleting the cookie.

a) the page A places a cookie "meow" that has an expiration time of one year
b) the user navigates in the page A, B, C, D, E, F and always has this cookie "meow" has an expiration time of one year
c) when the user happens in the Z page the cookie "meow" is set to have an expiry time in the past. The web browser will no longer send an expired cookie to the server. As far as the server sees, the cookie has been deleted.

This is what you want to happen, right?

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by Mariasole » Tue Mar 21, 2017 1:08 pm

Grazie per la tua pazienza e la tua ormai proverbiale gentilezza e disponibilità, caro SparkOut,
SparkOut wrote:a) the page A places a cookie "meow" that has an expiration time of one year
b) the user navigates in the page A, B, C, D, E, F and always has this cookie "meow" has an expiration time of one year
c) when the user happens in the Z page the cookie "meow" is set to have an expiry time in the past. The web browser will no longer send an expired cookie to the server. As far as the server sees, the cookie has been deleted.

This is what you want to happen, right?
I would like to see happen exactly that!

But I do a small example to make me understand (I know that my English is horrible).

Ok, a big breath and start...

The wonderful oeiuwyrceiuwyhtuieyhrtvohbghf.com site has many pages.
All are available except one which is absolutely prohibited. :wink:
On all pages except the forbidden (we'll call Z), there is a script that says:

Code: Select all

read cookie
if there is "purr" cookie shows the phrase "Hey, Elvis is not dead!"
if there is NOT a "purr" cookie create it with a validity of one year.
Here's the script of page Z:

Code: Select all

read cookie
if there is "purr" cookies do this:
deletes the cookie "purr" (or take it in the past, in short)
shows the phrase "Do not you care about Elvis? Go away in some hideous techno disco! Budgie!"
So let's see how it behaves the oeiuwyrceiuwyhtuieyhrtvohbghf.com site:

The user goes to the page, the page does not show anything, it can not find the "purr" cookie and then writes the cookie that is valid for one year.
The user goes to the page B (C, D, E, F, etc.), the page reads the cookie "purr" presence and then displays the message: "Hey, Elvis is not dead!"
The user goes to the page prohibited Z, the page reads the cookie and displays "You do not care Elvis? Go to some horrendous disco techno! Budgie!"; page "delete" the "purr" cookie
The user returns to page A, the page does not show anything because it does not find the cookie "purr" and then writes the cookie that is valid for one year. And so on...

I hope that I explained better! Thanks in advance!

Mariasole
(='.'=)

PS: Elvis is not dead! Really!

Code: Select all

                                   G   __
                                   \\  ,,)_
                                    \'-\( /
                                      \ | ,\
                                       \|_/\\
                                       / _ '.D
                                      / / \ |
                                     /_\  /_\
                            snd     '-    '-
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by Mariasole » Tue Mar 28, 2017 2:32 pm

Hi SparkOut, and all...
Do you have any idea how to solve my LCS cookie problem? :D
Thank you very much...

Mariasole
(='.'=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 366
Joined: Mon Jun 10, 2013 1:32 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by Lagi Pittas » Wed Mar 29, 2017 4:35 pm

Hi Maria,

I think you need to use cookies for what they were designed for - storing short messages.
What you are doing is using absence or presence as a flag.

Why not instead of deleting the cookie adding an extra item "DEL" using the "|" as the itemdelimeter on the end of the message when they go to Page Z?

So your script will then read the value of the cookie (into lcVal) as "You do not care about Elvis|DEL" if they have been to page Z or "Elvis is not dead" if they have not visited page Z

you could then extract item 2 of lcVal and if the second item is "DEL" or not empty do not write a new cookie put just print Item 1.

Infact unless I don't understand you do not even need to test or add item 2 because you have rewritten the Value of the Cookie - so the message is what you want them to see if they have gone to page Z

Regards Lagi

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: A biscuit and a cup of tea (things from the past) (='.'=

Post by Mariasole » Mon Apr 03, 2017 10:57 am

Dear Lagi,
thank you very much for your answer, but I do not understand well! :oops:
To the delight of SparkOut and Hermann in five months I'll just make the same question! :shock:
I can not fix it, even if friends who program in PHP tell me that in "their" language it is something easy and obvious to do! :x
But I do not give... then we feel between five months for this problem! 8)

Thank you very much to all!

Mariasole
(=^‥^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Post Reply