Click to See Complete Forum and Search --> : A few questions about cookies
SuzanneB
02-05-2007, 04:50 PM
Hello!
I need a cookie that lasts as long as is reasonable. Say a few years or something. How do I set one to expire in a couple of years? What is the practical limit to expiry? Is a few years ok?
AND..
Also I need to set a cookie for the current domain, but also for a second domain so that when the user visits that domain, the code can pick up the cookie. Is this possible? I don't see why not, I have just never tried it, that's all.
ptagi
02-06-2007, 12:13 AM
lifetime of a cookie => www.php.net (http://www.php.net/manual/en/function.setcookie.php)
You cannot set a cookie for different domains, would be a serious security leak don't you think :)
SuzanneB
02-06-2007, 03:46 AM
You know what, don't take this the wrong way, but I never understand why some folks answer questions by pointing to the manual. If I wanted to read the manual, I would have read the manual!!! I know where it it is!! My point is that the manual does not ( or at least I could not find where ) it talks about a maximum realistic time setting for a cookie. Hence, rather than continue to search, I asked on the forum. Only to be pointed back to the same page I was reading.
Also, is it entirely necessary to make fun of me when you answer my question? There is a domain parameter in the call, and I was wondering whether it could be used for other domains. No need to make fun of me.
I suppose then it checks it to ensure that any domain in the parameter is allowed?
So, I need to run a piece of code or pass a parameter to the other domain to get it to update it's cookie. That's a shame. Oh well.
ptagi
02-06-2007, 03:54 AM
SuzanneB,
it was not my point to make fun of you. The domain parameter is there to use on the same domain, in subdomains like forum.example.com and article.example.com so only forum.example.com can use the cookie.
About a maximum realistic time setting for a cookie is your own decision. Some take an hour, some take years. It depends on what you are gonna save into the cookie. I barely use cookies because it is client-side and I don't trust client-sides on my websites. No offecnce, you can use it to store a hash and check that hash into a database or something. That's quit save, but also point of guessing right.
SuzanneB
02-06-2007, 04:00 AM
OK! :-)
Now, of course, I need to ask another question, regarding setting a cookie on the other domain....
ptagi
02-06-2007, 04:05 AM
What is the purpose of using a cookie? remember logged in users or something else?
SuzanneB
02-06-2007, 05:07 AM
Hi,
Erm, sort of, it just remembers a setting that the user selected on the web site. The problem is that this setting is then used by several domains, that are "called" by the first ( well, the user is transferred to them). The setting also needs to be remembered for a long time. At the moment I am working on the idea of saving the data in a long term cookie, then reading and passing the data to the second domain when the user transfers to that second domain. The second domain will then also save it as a cookie so that when the user returns to the second domain, even if not via the first domain, it remembers the data.
NightShift58
02-06-2007, 04:51 PM
You could write a script that would run on each "receiving" server.
This script would take GET arguments such as ?id=234&setting=123 from the "sending" server.
The receiving serve would process, store and respond anything you wanted.
To call these "satellites" or "tunnel" scripts, use file_get_contents().