/    Sign up×
Community /Pin to ProfileBookmark

A few questions about cookies

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.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ptagiFeb 06.2007 — lifetime of a cookie => www.php.net

You cannot set a cookie for different domains, would be a serious security leak don't you think ?
Copy linkTweet thisAlerts:
@SuzanneBauthorFeb 06.2007 — 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.
Copy linkTweet thisAlerts:
@ptagiFeb 06.2007 — 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.
Copy linkTweet thisAlerts:
@SuzanneBauthorFeb 06.2007 — OK! :-)

Now, of course, I need to ask another question, regarding setting a cookie on the other domain....
Copy linkTweet thisAlerts:
@ptagiFeb 06.2007 — What is the purpose of using a cookie? remember logged in users or something else?
Copy linkTweet thisAlerts:
@SuzanneBauthorFeb 06.2007 — 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.
Copy linkTweet thisAlerts:
@NightShift58Feb 06.2007 — You could write a script that would run on each "receiving" server.

This script would take GET arguments such as [B]?id=234&setting=123[/B] 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().
×

Success!

Help @SuzanneB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...