Page 1 of 2
A biscuit and a cup of tea (things from the past) (='.'=)
Posted: Tue Mar 14, 2017 5:35 pm
by Mariasole
Hello everyone!
I would like to ask you something about the biscuits, or...
the cookies
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".
Obviously I can not.
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
(='.'=)
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Tue Mar 14, 2017 7:19 pm
by FourthWorld
That Lesson seems to cover that. What happened when you tried it?
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Tue Mar 14, 2017 7:36 pm
by Mariasole
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
(=^‥^=)
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Tue Mar 14, 2017 8:22 pm
by SparkOut
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)
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Wed Mar 15, 2017 3:25 pm
by Mariasole
Carissimo e gentilissimo SparkOut,
probably I'm completely inept!
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
(=^‥^=)
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Wed Mar 15, 2017 6:13 pm
by [-hh]
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

Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Wed Mar 15, 2017 6:59 pm
by Mariasole
Carissimo e gentilissimo Hermann,
anzi dovrei dire
squisitamente gentile Hermann
Did you see how I'm constant?
Months and months to be able to solve a problem!
But I still can not ...
Thanks for letting me finally explained how it works LCS Cookies Management System!
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...
Mariasole
(=^‥^=)
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Wed Mar 15, 2017 8:59 pm
by SparkOut
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.....
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Wed Mar 15, 2017 9:02 pm
by [-hh]
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.
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Fri Mar 17, 2017 7:22 pm
by Mariasole
Thank you so much for your help carissimi e gentilissimi SparkOut and
Hermann!
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!
Instead LCS writes all 3 cookies, but the web server deletes it (true Hermann?).
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).
Then
SparkOut script's works perfectly!
I'm the one who did not work perfectly, or rather, I am too ignorant!
That said, let's get to what I want to do for months!
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?
Grazie davvero a tutti!
Miao! (meow ---> miao in italian)
Mariasole
(=^‥^=)
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Fri Mar 17, 2017 7:30 pm
by SparkOut
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?
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Tue Mar 21, 2017 1:08 pm
by Mariasole
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.
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, t
he 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 '- '-
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Tue Mar 28, 2017 2:32 pm
by Mariasole
Hi
SparkOut, and all...
Do you have any idea how to solve my LCS cookie problem?
Thank you very much...
Mariasole
(='.'=)
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Wed Mar 29, 2017 4:35 pm
by Lagi Pittas
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
Re: A biscuit and a cup of tea (things from the past) (='.'=
Posted: Mon Apr 03, 2017 10:57 am
by Mariasole
Dear
Lagi,
thank you very much for your answer, but I do not understand well!
To the delight of
SparkOut and
Hermann in five months I'll just make the same question!
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!
But I do not give... then we feel between five months for this problem!
Thank you very much to all!
Mariasole
(=^‥^=)