473,378 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 6220

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
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...
3
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?...
3
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...
3
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...
8
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...
3
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...
1
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...
21
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.