Cookie gets changed when hit comes from a referrer

Νίκος Αλεξόπουλος nikos.gr33k at gmail.com
Wed Oct 9 04:24:35 EDT 2013


Στις 9/10/2013 4:33 πμ, ο/η Steven D'Aprano έγραψε:
> On Wed, 09 Oct 2013 01:52:44 +0300, Νίκος Αλεξόπουλος wrote:
>
>> Is there something i can try to isolate the problem and make it work?
>
> Of course there is. That is part of the job of the developer: hard work
> trying dozens, maybe hundreds of different things until you isolate the
> problem. There are no shortcuts, no magic button you can push to
> immediately identify the source of the problem.
>
> If you are not willing to spend hours, maybe days or weeks, working on
> this problem, then you should hire a programmer who is, and stop fooling
> yourself that you are a professional developer. An amateur who programs
> for fun can just give up when a problem becomes too difficult and isn't
> fun any more. A professional has to keep going.
>
> Start by identifying which browsers this occurs on. You should test using
> at least Firefox, Internet Explorer, Safari, Chrome and Opera, for as
> many different versions as you can find. You should also test with less
> common browsers such as Konqueror, Epiphany, lynx, links and others. See
> if there is a pattern in which ones behave as you expect and which ones
> don't.
>
> You should also test with and without cookies enabled, ad-blockers, and
> similar. Maybe you can replicate the problem if (say) the user accepts
> the first cookie, then rejects it when they click Back.
>
> If this only occurs with a single version of a single browser with
> cookies enabled and no ad blocker, you should report it as a bug to the
> browser developers. Make sure you give them enough detail to replicate
> the problem. If it's an old version, they'll probably say Won't Fix, and
> you'll just have to accept that your cookie handling code won't work for
> some percentage of visitors.
>
> Have you checked that the server is setting the cookie values you expect?
> Have you checked the value of the cookie in the browser? If you don't
> know how to do these things, this site will teach you everything you need:
>
> https://duckduckgo.com/
>
> Follow the links until you reach enlightenment. There are *thousands* of
> pages on debugging programming problems.
>
> If you find it is broken with *all* of the above browsers, then you
> should suspect a bug in your Python code. In that case, since other
> people have failed to reproduce the reported problem, you are obviously
> doing something different than what you are telling us you are doing.
> Only in this case should you come back here to ask for help with your
> Python code. Before you do, read this, and follow the instructions:
>
> http://www.sscce.org/
>
> If you are not willing to do these things, then stop pretending to be a
> professional developer, and admit that you are only programming for fun.
> There is no shame in this -- not everyone is cut out to be a professional
> programmer, just as not everybody makes a good doctor or taxi driver or
> carpenter.
>
>
>> By whole counters project is based on cookie handling now....
>
> If you cannot solve the cookie problem, maybe you should reconsider the
> decision to rely on cookies.
>
>
>
I managed t overcome it like this:

cur.execute('''UPDATE visitors SET cookieID = %s, host = %s, city = %s, 
useros = %s, browser = %s, ref = %s, hits = hits + 1, lastvisit = %s 
WHERE counterID = %s and host = %s''',
						(cookieID, host, city, useros, browser, ref, lastvisit, cID, host) )
		
if not cur.rowcount:
# if first time visitor on this page, create new record, if visitor 
exists then update record
cur.execute('''INSERT INTO visitors (counterID, cookieID, host, city, 
useros, browser, ref, lastvisit) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
ON DUPLICATE KEY UPDATE host = %s, city = %s, useros = %s, browser = %s, 
ref = %s, hits = hits + 1, lastvisit = %s''',
(cID, cookieID, host, city, useros, browser, ref, lastvisit, host, city, 
useros, browser, ref, lastvisit) )


But thats a not clear way to handle the cookie because i involve host to 
help me identify its recorde since when my website hit comes from areferrer.

i also tried adding the domain when i set the cookie but this didnt 
helped me at all:

# initialize cookie and retrieve cookie from clients browser
cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )

if cookie.get('ID') is not None:
	cookieID = cookie['ID'].value
else:
	cookieID = random.randrange(0, 9999)
	cookie['ID'] = cookieID
	cookie['ID']['domain'] = ".superhost.gr"
	cookie['ID']['path'] = '/'
	cookie["ID"]["expires"] = 60*60*24*365		# this cookie will expire in a year

i read some links from duckduckgo but that didnt help me solve this.
Please someone esle try to reproduce the problem by just using cgi and 
not mod_wsgi.

ps. Really why duckduckgo and not google.com ?




More information about the Python-list mailing list