DIGIT-ARC read-only archive · snapshot: July 23, 2026

Little Javascript/Cookie Help..

5 posts · originally from https://geek.digit.in/community/threads/little-javascript-cookie-help.90829/

R
REY619 Original post #1
Jun 19, 2008 at 9:41 AM
Hi people.. I have a little problem.. I need to put a javascript code in a html file, which when viewed, get the cookies of the viewer and store them in a remote txt file..
i know we can get the cookies with this -
Code:
javascript:alert(document.cookie)
or
Code:
javascript:document.write(document.cookie)
but how to store the value of
Code:
(document.cookie)
in a txt file which is located at, say, *www.blah.com/logs/logs.txt??

I hope you understand.

Thanx.
victor_rambo
Jun 19, 2008 at 1:19 PM
Before I can help you, I need to know why you want to store all cookies of an visitor? Cookies may contain critical information and be used for illegal activities. In plain words, you are violoating your visitors privacy.
siddes
siddes #3
Jul 1, 2008 at 4:36 PM
You cannot store the cookies in a file through Javascript, unless you use JScript and your target uses Internet Explorer.
victor_rambo
Jul 1, 2008 at 8:20 PM
he wants to store it in a 'remote' file.
amitava82
Jul 2, 2008 at 3:25 AM
you have to use server side scripting language in order to be able to write data to server. Here is how you do it with PHP:

PHP:
<?php
$filename = rand(0000,9999).'.txt';
$filehandler = fopen($filename,'w');
$cookies = print_r($_COOKIE, true);
fwrite($filehandler,$cookies);
fclose($filehandler);
?>