473,786 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Server side cookie problems

Hi, I am trying to set a cookie on a client computer using the Cookie
module however all I get is the text being printed in the browser
window. Can anyone point me in the right direction so that the cookie
data is set without it appearing in the browser? A shortened version
of the code is below, in the full version there is also userID check,
this seems to work ok. I have removed that portion for the time being
as its the writing part that is the problem.

import sys, os, string, cgi, Cookie, urllib2
from types import ListType

cookie = Cookie.SimpleCo okie()
cookieHdr = os.environ.get( "HTTP_COOKI E", "")
cookie.load(coo kieHdr)

def writetocookie(n umber):
#writes the ID of the database entry to a cookie
cookie["dataid"]=number
print "Content-Type: text/html"
print
print "Set-Cookie: dataid=",cookie["dataid"].value
writetocookie(1 )

I presume this is not the correct way to write a cookie, the examples
I have found online don't seem to provide much more information.

Kind regards,

rod
Feb 6 '08 #1
4 1268
En Wed, 06 Feb 2008 15:27:53 -0200, rodmc <us************ ***@yahoo.co.uk >
escribi�:
Hi, I am trying to set a cookie on a client computer using the Cookie
module however all I get is the text being printed in the browser
window. Can anyone point me in the right direction so that the cookie

def writetocookie(n umber):
#writes the ID of the database entry to a cookie
cookie["dataid"]=number
print "Content-Type: text/html"
print
print "Set-Cookie: dataid=",cookie["dataid"].value
I presume this is not the correct way to write a cookie, the examples
I have found online don't seem to provide much more information.
I don't know either if this is the right way, but surely the Set-Cookie
header must appear *before* the blank line; that blank line separates the
headers from the response body.

--
Gabriel Genellina

Feb 6 '08 #2
On Feb 6, 8:00 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
En Wed, 06 Feb 2008 15:27:53 -0200, rodmc <userprogoogl e-...@yahoo.co.uk >
escribi�:
Hi, I am trying to set a cookie on a client computer using the Cookie
module however all I get is the text being printed in the browser
window. Can anyone point me in the right direction so that the cookie
def writetocookie(n umber):
#writes the ID of the database entry to a cookie
cookie["dataid"]=number
print "Content-Type: text/html"
print
print "Set-Cookie: dataid=",cookie["dataid"].value
I presume this is not the correct way to write a cookie, the examples
I have found online don't seem to provide much more information.

I don't know either if this is the right way, but surely the Set-Cookie
header must appear *before* the blank line; that blank line separates the
headers from the response body.

--
Gabriel Genellina
Thanks, that seemed to work.

rod
Feb 7 '08 #3
On Feb 7, 1:06 pm, rodmc <userprogoogl e-...@yahoo.co.uk wrote:
On Feb 6, 8:00 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
En Wed, 06 Feb 2008 15:27:53 -0200, rodmc <userprogoogl e-...@yahoo.co.uk >
escribi�:
Hi, I am trying to set a cookie on a client computer using the Cookie
module however all I get is the text being printed in the browser
window. Can anyone point me in the right direction so that the cookie
def writetocookie(n umber):
#writes the ID of the database entry to a cookie
cookie["dataid"]=number
print "Content-Type: text/html"
print
print "Set-Cookie: dataid=",cookie["dataid"].value
I presume this is not the correct way to write a cookie, the examples
I have found online don't seem to provide much more information.
I don't know either if this is the right way, but surely the Set-Cookie
header must appear *before* the blank line; that blank line separates the
headers from the response body.
--
Gabriel Genellina

Thanks, that seemed to work.

rod
Also how do I find out if a cookie has expired? I have tried various
methods but to no avail?

Cheers,

rod
Feb 7 '08 #4
En Thu, 07 Feb 2008 10:40:58 -0200, rodmc <us************ ***@yahoo.co.uk >
escribi�:
Also how do I find out if a cookie has expired? I have tried various
methods but to no avail?
The browser won't send the cookie in that case. The server cannot tell
whether the cookie expired or it never existed, AFAIK.

--
Gabriel Genellina

Feb 7 '08 #5

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

Similar topics

17
1846
by: neerolyte | last post by:
how would i go about setting a cookie in javascript that can be read in javascript on the next page load, but will NOT be passed to the server?
1
1740
by: HorseGeek | last post by:
I have three servers: Server1, Server2, and Server3. There is a login cookie does not expire for SOME users on Server2. Ironically, the login cookie expires correctly for ALL users on the Server1 and Server3 websites. This seems to imply a problem with the user's browser settings ... except the users that have consistent problems with the Server2 are able to read the logon cookie and other cookies which control navigation to the...
0
1944
by: Robin Day | last post by:
I have a page that contains some dhtml and uses client side cookies so store it's current state so that on clicking the "back" button to it the page will be as the user last saw it. However, should the user click on a link to that page, I want to remove the cookie so that the page is displayed in its default state. The two ways I can think of doing this is to either have some javascript code to delete the cookie when the page is first...
3
11124
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the codebehind then I actually end up with TWO cookies with the same name in the response. The cookie...
6
2297
by: Andre Ranieri | last post by:
I'm trying to create a login page for customers to log into our corporate website, our presidents naturally wants the user and password fields to populate from a cookie so the customer doesn't have to type their credentials every time, this seems like a pretty common thing. However, when I try to populate the password HTML textbox from the cookie, the textbox remains blank. However, if I try this from an equivalent web control, the...
2
6252
by: HopfZ | last post by:
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);
5
5918
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, Is there an easier way to handle that? I used Javascript to handle this when our two domains are hosted on two different servers(on different networks) and our search engine marketing people don't like the javascript links since they think the links are not favorable to a search robot. Now our company is thinking about hosting these two domians on the same server, So I am wodering if there is any easy way to do that. Would you...
2
2142
by: arijitdas | last post by:
Hi, We have an ASP.NET 2.0 web application where we want to share few user specific data between server and client side code using cookie. We are seeing a very strange behavior that it does not work consistently. Sometimes we are getting the latest value set from server in client script, sometimes were are getting a wrong (previously set old) value. In other words, the values in client and server is not in sync. Can anybody suggest...
0
10363
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
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6748
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.