473,583 Members | 4,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cookie is sent to server even if it's generated by javascript?

Server sends cookie to browser and the browser send the same cookie
back to the server according to Wikipedia.
Do browsers send even javascript-generated cookie to servers?

For example, if I browse to a page on a server and if the content of
the page is the following:

<html>
<head><script >
alert(document. cookie);
var n = prompt('your new name');
document.cookie = 'name='+n+'; path=/; expires= Fri, 31-Dec-2010
23:59:59 GMT';
</script></head>
<body></body>
</html>

Will the browser send the generated cookie to server next time I visit
the page, even if it's not necessary to send the cookie to server in
this case?

Jan 4 '07 #1
2 6237

HopfZ skrev:
Server sends cookie to browser and the browser send the same cookie
back to the server according to Wikipedia.
Do browsers send even javascript-generated cookie to servers?

For example, if I browse to a page on a server and if the content of
the page is the following:

<html>
<head><script >
alert(document. cookie);
var n = prompt('your new name');
document.cookie = 'name='+n+'; path=/; expires= Fri, 31-Dec-2010
23:59:59 GMT';
</script></head>
<body></body>
</html>

Will the browser send the generated cookie to server next time I visit
the page, even if it's not necessary to send the cookie to server in
this case?
Yes, it will send the cookie to the server next time you visit any page
on that server.

Jan 4 '07 #2
HopfZ wrote:
Server sends cookie to browser and the browser send the same cookie
back to the server according to Wikipedia.
Do browsers send even javascript-generated cookie to servers?
Yes, the cookie is always sent back, since "Cookie: " becomesa line in
the HTTP-header set if the browser finds out that the domain in
question holds cookie-data for it. But for javascript-cookies that
doesn't matter; they reside in the browser's own memory and are not
derived from the HTTP-headers (possibly the start value of
document.cookie might get its content from the HTTP-headers (?) but
certainly not afterwards).
For example, if I browse to a page on a server and if the content of
the page is the following:

<html>
<head><script >
alert(document. cookie);
var n = prompt('your new name');
document.cookie = 'name='+n+'; path=/; expires= Fri, 31-Dec-2010
23:59:59 GMT';
</script></head>
<body></body>
</html>

Will the browser send the generated cookie to server next time I visit
the page, even if it's not necessary to send the cookie to server in
this case?
Yes, always (supposed the browser is allowed to do so, obviously).

Actually the core mechanism of cookies is quite simple, server could
say:

Content-type: text/html
Set-Cookie: foo=bar; path=/; expires Mon, 09-Dec-2002 13:46:00 GMT

and when browser requests a page from the same domain, then it will do
something like

Content-type: text/html
Cookie: foo=bar

Now javascript cookies differ significantly from server-side cookies,
since javascript cookies can be edited dynamically/repeatedly from
within a web page. Traditional cookies (as the example transfer above)
can only belong to one single HTTP request.

But javascript has access to the internal memory of the browser, which
allows the browser to read and write cookiedata on-the-fly. It doesn't
have the limitations of HTTP because javascript is executed on the
client, and cookies reside at the client as well. So the browser can
directly read from and write to local (cookie-)files. Changes to
cookies from javascript take place immediately.

Hope this helps,

--
Bart

Jan 4 '07 #3

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

Similar topics

1
4068
by: Renuka | last post by:
Hello, Can someone help me with the following situation?? I have a Hyperlink within a String like below: sSql = "SELECT DISTINCT " + "'Action' = '<center><a href='+char(34)+'ChangeRequest.aspx?ID='+cast(ChangeRequest.ChangeRequest_ID as nvarchar) +CHAR(34)+'>Open</a></center>',"
3
6772
by: David Shorthouse | last post by:
Hey folks, Not an off-topic posting.....since I was shot-down in an earlier post...this one's legit. How do I go about calling a server-side vbscript within a client-side javascript function? What I have is a page heavy on the javascript that has a number of functions, one of which is to begin a visual countdown with an onclick and also...
3
4198
by: HorseGeek | last post by:
I can't find a cookie that my code is writing. The behavior of my webpages indicates that the cookie IS being written SOMEPLACE. However, I can't find it. My client does not want the code going into production unless they can actually see where the cookie is being written. They are concerned that the cookie may stay around after they...
3
1811
by: ~J~ | last post by:
Hi everyone I'm positive this is possible, just never needed it until now and I don't have a clue where to start I have an XML document that is attached to an XSL style sheet, within this XSL there is some javascript commands that are attached to certain HTML controls What I want to do is when the user clicks on an HTML generated code...
8
5429
by: CsaaGuy | last post by:
I have a requirement to disable some textboxs depending on their contents. I choose to do this by invoking some javascript. When they change the contents, i disable the textbox they just put new data into and focus on another textbox. My logic works fine, the textboxes get disabled. However, when the page posts back, the disabled textbox...
3
1344
by: Nathan Sokalski | last post by:
I have a VB.NET function that I am using in an ASP.NET page. The code creates a String, which contains && (the JavaScript Logical AND operator) and is used as part of the JavaScript sent to the browser. However, ASP.NET is converting this to &amp; even though it is intended to be part of the JavaScript. This is causing my JavaScript not to work...
1
1428
by: GpOscar | last post by:
Hey whats up.. i have created a form which does calculations i have installed it on the server and run on it all the other workstations. Now on this form there are some rates that change according to calculations. how can i retrieve the cookies from the server rather than stored on each individual workstation.? so that all the...
21
1852
by: TonyV | last post by:
Hi all, I'm trying to use some javascript code in Internet Explorer 6.0 that's being generated by a Perl file. I have a line in my header that looks something like this: <script src="jscode.pl?parm1=foo&parm2=monkey" type="text/javascript" / Just for the sake of simplicity, here's a very simplified version of the Perl code:
0
7825
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8191
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5700
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...
0
5372
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3816
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...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2331
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
1
1431
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1155
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...

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.