Click to See Complete Forum and Search --> : copy a cookie
domuk
11-10-2003, 03:42 AM
Is it possible to write a PHP script to save/ copy a cookie to the A-drive from the C drive?
Also remove a cookie (with PHP) that has just been created using a javascript command on say a user closing a HTML doc?
Your help will be appreciated,
Thanks in advance,
Dom.
Originally posted by domuk
Is it possible to write a PHP script to save/ copy a cookie to the A-drive from the C drive?
Not that I know of...
Also remove a cookie (with PHP) that has just been created using a javascript command on say a user closing a HTML doc?
You can access cookies in PHP that were written with JavaScript, but since PHP runs server-side, how will your script know when you close the HTML document? What I would do is just not set a expiration date on the cookie when you set it. This way, when the user closes their browser, it will get deleted.
domuk
11-10-2003, 07:54 AM
thanks pyro..
I have just started looking at cookies and have been reading up on them this morning....:eek:
What i am trying to do is store and retrieve variables that can be reused in calculations at a later date (or the same date).
From this mornings reading I have realised that if i don't set an exp. date on the cookie that it will be deleted when the user closes the html page.
I need a simple example along these lines that i can try and understand....
Any suggestions?
Sure, try something like this.
setcookie("cookiename", "cookievalue", time()+60*60*24, "/");If you look in the manual at php.net, you'll see that the setcookie function takes the following paramaters:
bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])So, the above example is telling it to expire in one day (time() returns the seconds).
To read the cookie, you would then use something like this:
$_COOKIE['cookiename']Also, remember that headers (including cookies) must be sent before any output is started to the browser. So, you must set the cookie before any output has started, but you can read it at any time.
domuk
11-11-2003, 10:55 AM
thanks pyro