[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Server side cookie problems

rodmc

2/6/2008 5:28:00 PM

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.SimpleCookie()
cookieHdr = os.environ.get("HTTP_COOKIE", "")
cookie.load(cookieHdr)

def writetocookie(number):
#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
5 Answers

Gabriel Genellina

2/6/2008 7:00:00 PM

0

En Wed, 06 Feb 2008 15:27:53 -0200, rodmc <userprogoogle-139@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(number):
> #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

rodmc

2/7/2008 12:07:00 PM

0

On Feb 6, 8:00 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
> En Wed, 06 Feb 2008 15:27:53 -0200, rodmc <userprogoogle-...@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(number):
> > #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

rodmc

2/7/2008 12:41:00 PM

0

On Feb 7, 1:06 pm, rodmc <userprogoogle-...@yahoo.co.uk> wrote:
> On Feb 6, 8:00 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
>
>
>
> > En Wed, 06 Feb 2008 15:27:53 -0200, rodmc <userprogoogle-...@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(number):
> > > #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

Gabriel Genellina

2/7/2008 5:25:00 PM

0

En Thu, 07 Feb 2008 10:40:58 -0200, rodmc <userprogoogle-139@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

Sir John Howard

10/21/2008 11:21:00 AM

0

Dean Jones wrote:

> Dirty muzzies!

Hanging's too good for them!

> On Oct 20, 11:47?pm, Sir John Howard <sirjwhow...@gmail.com> wrote:
> > Media attacked as Merrylands attackers jailed
> >
> > http://www.smh.com.au/news/national/media-attacked-in-sydne......
> >
> > Six youths have been arrested outside Parramatta Children's Court
> > after several members of the media were attacked.
> >
> > A photographer and a cameraman were injured after the sentencing of
> > five teenagers who rampaged through a western Sydney school with
> > baseball bats, a machete and a sword on April 7.
> >
> > The five youths, who are aged between 14 and 17 and cannot be named,
> > have been sentenced to jail time for their crimes at Merrylands High
> > School in Merrylands West.
> >
> > They assaulted seven students and two teachers before smashing windows
> > and doors, causing more than $15,000 in damage as the school went into
> > lockdown.
> >
> > Together the youths faced a total of 101 charges, including multiple
> > counts of assault, affray, malicious damage, as well as participating
> > in a criminal group.
> >
> > At Parramatta Children's Court today, Magistrate Sharon Holdsworth
> > sentenced four of the youths to a maximum each of twelve months and
> > three weeks in jail, with a non-parole period of eight months.
> >
> > The fifth teenager received a maximum sentence of 17 months for
> > affray, with a non-parole period of 12 months and three weeks.
> >
> > One of the youths who faced a maximum of 12 months applied for bail
> > today, which was formerly refused.
> >
> > Outside court, violence erupted as supporters of the youths being
> > sentenced attacked a photographer and a cameraman who were at the
> > court to report on the case.
> >
> > Six teenagers were arrested at the scene and taken for questioning at
> > Parramatta police station, police said.
> >
> > Police are reportedly reviewing media footage taken during the alleged
> > assaults.
> >
> > A photographer sustained a serious cut to his eye after his camera was
> > allegedly pushed into his face by one of the attackers, who were aged
> > between 15 and 18, police said.
> >
> > A number of people left the scene after the altercation, police said.
> >
> > Police are urging anyone who witnessed the incident to contact
> > Parramatta Police or Crimestoppers on 1800 333 000.