473,748 Members | 2,243 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 1267
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
1842
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
1739
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
1939
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
11122
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
2140
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
8818
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9355
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
9307
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
9225
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8234
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 projectplanning, coding, testing, and deploymentwithout 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
6790
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
6069
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();...
1
3296
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
3
2203
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.