473,661 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple javascript cookie question

Hi guys,

I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referr er
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail so i
can see how people got to my website and where they entered.

Many thanks

Alex
Hot Tubs 2 Buy.co.uk

Your help would be much apreciated.

Sep 5 '06 #1
6 2112
alex.kemsley wrote on 05 sep 2006 in comp.lang.javas cript:
I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referr er
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail so i
can see how people got to my website and where they entered.
How can we know the script is so simple
if you do not show us wat you wrote?

What is a "formail"?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 5 '06 #2
form mail.
As in an email program that sends you the content in a form.
Thank
Alex

Evertjan. wrote:
alex.kemsley wrote on 05 sep 2006 in comp.lang.javas cript:
I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referr er
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail so i
can see how people got to my website and where they entered.

How can we know the script is so simple
if you do not show us wat you wrote?

What is a "formail"?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 5 '06 #3
alex.kemsley wrote on 05 sep 2006 in comp.lang.javas cript:
Evertjan. wrote:
>alex.kemsley wrote on 05 sep 2006 in comp.lang.javas cript:
I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referr er
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail
so i can see how people got to my website and where they entered.

How can we know the script is so simple
if you do not show us wat you wrote?

What is a "formail"?
[please do not toppost on usenet]
form mail.
As in an email program that sends you the content in a form.
Is that a clientside thing? Or do you simply send the daa to servrside to
be processed, and if so how?

Because you did toppost,
you did not consider my first and far more important question:
What code did you come up with?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 5 '06 #4
*** alex.kemsley escribió/wrote (5 Sep 2006 07:13:54 -0700):
I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable
[...]
I need this cookie to last just one day.
I compiled these functions some time ago, I hope it helps. (I've just translated the names from Spanish using Search & Replace, I hope I didn't break it)
/*
* Creates a cookie - name [value] [timeToExpire (s)] [path] [domain] [secure (bool)]
*/
function createCookie(na me, value, timeToExpire, path, domain, secure){ // v2005-03-02
if(timeToExpire ){
var expires=new Date();
expires.setUTCM illiseconds(exp ires.getUTCMill iseconds()+1000 *timeToExpire);
}

document.cookie =escape(name) + '=' + (value? escape(value) : '') +
(expires? '; expires=' + expires.toGMTSt ring() : '') +
(path? '; path=' + escape(path) : '') +
(domain? '; domain=' + escape(domain) : '') +
(secure? '; secure' : '');
}
/*
* Removes a cookie
*/
function removeCookie(na me){ // v2005-03-02
createCookie(na me, '', -86400*365*10);
}
/*
* Returns the value of a cookie (null if it doesn't exist)
*/
function readCookie(name ){ // v2005-02-27
eval('var re=/^('+escape(name )+')=(.*)$/i;');
var c=document.cook ie.split(/;\s*/);

for(var i in c){
if(re.test(c[i])){
return unescape(re.exe c(c[i])[2]);
}
}
return null;
}

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 5 '06 #5
JRS: In article <v1************ **************@ 40tude.net>, dated Wed, 6
Sep 2006 00:13:20 remote, seen in news:comp.lang. javascript, Alvaro G.
Vicario <we*******@NOSP AMdemogracia.co mposted :
>I need this cookie to last just one day.

I compiled these functions some time ago, I hope it helps. (I've just translated
the names from Spanish using Search & Replace, I hope I didn't break it)
If you had likewise replaced Tab with Space Space, it would have been
easier to read.

var expires=new Date();
expires.setUTCM illiseconds(exp ires.getUTCMill iseconds()+1000 *tim
eToExpire);
That has (FWIW) an error of the present fraction of a second, and ISTM
may use conversions to/from YMD internally.

expires.setTime ( +expires + 1000*timeToExpi re )
or just
expires=new Date( +new Date() + 1000*timeToExpi re )
>function removeCookie(na me){ // v2005-03-02
createCookie(na me, '', -86400*365*10);
}
Is it necessary to go 10 years ago?

eval('var re=/^('+escape(name )+')=(.*)$/i;');
Function eval should not be needed.

It's a good idea to read the newsgroup and its FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 6 '06 #6
"alex.kemsl ey" <al**********@h ottubs2buy.co.u kwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Hi guys,

I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referr er
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail so i
can see how people got to my website and where they entered.
I've a cookie abstraction library that might help here:

http://www.depressedpress.com/Conten...kies/Index.cfm

There is one sorta bug in this version (which I hope to fix tomorrow): the
erase() method doesn't accept a path or domain which means it will fail with
cookies which set path and domain (instead of deleting the named cookie it
will create a second cookie without the path or domain).

If you're not doing that then it should work, if you are don't use the
erase() method for now and instead reset the cookie (the set() method) to a
past date to delete it.

Jim Davis
Sep 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2664
by: mark leeds | last post by:
i am not a javasript programmer by any stretch but i have been writing a javascript programmer for a friend that does the following : 1) prompts the user for first name, middle name and last name 2) saves the data in a cookie 3) spits the cookie data back out to the respective fields
7
2112
by: Steph | last post by:
Bonjour, Je souhaite lancer une redirection vers un fichier php via SRC= dans une condition if (voir ci-dessous en bas du script) mais la redirection ne fonctionne pas. Par contre la condition est bien validée car le cookie (crée précédemment) est bien effacé par SetCookie. Pourriez-vous me dire ce qui ne va pas ? Merci d'avance Steph
0
1820
by: JT | last post by:
I posted a question earlier about communicating between a javascript function and vb.net. In the end I decided to try using a cookie. I use the following javascript function (from vb.net) to set the cookie: sb.Append("<script language='javascript'>") sb.Append("{if (confirm('Are you sure? ') == true)") sb.Append("{var date = new Date(); date.setTime(date.getTime()+(60*60*1000)); var expires = ' expires='+date.toGMTString();...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.