bigup401 has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: auto create cookies
by hippo (Archbishop) on Jan 25, 2019 at 11:30 UTC | |
is it possible to create cookies automatically when i open the page and replace the cookies with other value every time the page is opened Yes. | [reply] |
by bigup401 (Pilgrim) on Jan 25, 2019 at 12:12 UTC | |
ok here is my try. but the script keeps redirecting and getting error in browser. i want to set cookies then continue doing other thing on same page
the main solution i want. is to redirect once. if the page is opened | [reply] [d/l] |
by hippo (Archbishop) on Jan 25, 2019 at 12:29 UTC | |
i want to set cookies then continue doing other thing on same page In which case, don't redirect. | [reply] |
by bigup401 (Pilgrim) on Jan 25, 2019 at 14:41 UTC | |
by hippo (Archbishop) on Jan 25, 2019 at 15:00 UTC | |
| |
|
Re: auto create cookies
by marto (Cardinal) on Jan 25, 2019 at 11:14 UTC | |
You asked delete cookie. | [reply] |
by bigup401 (Pilgrim) on Jan 25, 2019 at 11:23 UTC | |
i thought this. cookies are created on submit. not auto creating itself when page opens | [reply] |
by marto (Cardinal) on Jan 25, 2019 at 11:31 UTC | |
"i thought this. cookies are created on submit. not auto creating itself when page opens" You wrote Re^2: delete cookie (cgi101). If you don't want to wait for a submit, why would you? Before posting re-read your previous questions on the same topics, I've already given you links to documents teaching you how all of the works, maybe you should spend time reading that. Again your strategy for working is fundamentally flawed. | [reply] |
|
Re: auto create cookies
by harangzsolt33 (Deacon) on Jan 27, 2019 at 20:27 UTC | |
(JavaScript is very similar to Perl in syntax, and in addition, you can use the $ sign anywhere in a variable name. Or you may decided to not use it at all. It's up to you. If you like to write code that resembles perl, you can start each variable name with a dollar sign. There is absolutely no difference between a ' and " signs for declaring strings. You use whichever you like. Also, instead of using a dot to merge two strings, you must use a plus sign.) So, anyway, you just put this in a HTML file, and it will create a cookie called "MyCookie" which expires in 5 years, and then it will read that same cookie. And if the read is successful, then it prints that cookies are working fine. So, it's a simple code. Your perl program would simply print this entire block anywhere within the HTML file, and if you want to change the value of the cookie, just make sure it's a valid string. The string declaration in JavaScript is just like in C or C++. Same syntax. Also, you may not include any special characters in a cookie value other than listed in a variable named $COOKIEJAR. So, those are the only valid characters you may use in a cookie. The difference between localStorage is that you may store any kind of binary data in localStorage. LocalStorage is usually 10 MB in size. Cookies can only store up to 5 KB, and if your website creates more than what fits in that space, then you simply won't be able to create anymore cookies. You have to delete some in order to free up some space. Cookies also have expiration, while localStorage does not have expiration. Also, whatever you put in localStorage does not get sent back to the server with each page request. So, they are hidden. Only the JavaScript program can read and write to localStorage. Note: Some very old browsers used in old smart phones do not support localStorage. And some browsers may have cookies turned off but localStorage is enabled! So, if it is an absolute MUST for you to store something on the visitor's computer, then you should check both cookies and localStorage to see which one is available and working.
| [reply] [d/l] |
by marto (Cardinal) on Jan 28, 2019 at 09:20 UTC | |
You may want to check some of your stated limits. RFC 6265 HTTP State Management Mechanism:
| [reply] [d/l] |
by harangzsolt33 (Deacon) on Jan 28, 2019 at 20:42 UTC | |
| [reply] |