Under what conditions do you want to execute the block?
This:
mycookie and mycookie.value != 'nikos'
will be true if:
there _is_ a cookie, but its value isn't 'nikos'
I think that you want is to execute the block if someone else is
visiting. Correct?
Yes that exactyl right!
To make sure a cookie is set i have a script names koukos.py
containing this:
==============================
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cgitb; cgitb.enable()
import cgi, os, Cookie
# initialize cookie
cookie = Cookie.SimpleCookie()
cookie.load( os.environ.get('HTTP_COOKIE', '') )
mycookie = cookie.get('visitor')
htmlBody = []
# if visitor cookie does exist
if ( mycookie and mycookie.value == 'nikos' ):
htmlBody.append('ΑΠΟ ΤΗΠΕΠΟΜΕÎΗ ΕΠΙΣΚΕΨΗ ΣΟΥ ΘΑ ΣΕ ΥΠΟΛΟΓΙΖΩ ΩΣ
ΕΠΙΣΚΕΠΤΗ ΑΥΞΑÎΟÎΤΑΣ ΤΟΠΜΕΤΡΗΤΗ!')
cookie['visitor'] = 'nikos'
cookie['visitor']['expires'] = -1 #this cookie will expire
now
else:
htmlBody.append('ΑΠΟ ΔΩ ΚΑΙ ΣΤΟ ΕΞΗΣ ΔΕΠΣΕ ΕΙΔΑ, ΔΕΠΣΕ ΞΕΡΩ, ΔΕÎ
ΣΕ ΑΚΟΥΣΑ! ΘΑ ΕΙΣΑΙ ΠΛΕΟΠΟ ΑΟΡΑΤΟΣ ΕΠΙΣΚΕΠΤΗΣ!!')
cookie['visitor'] = 'nikos'
cookie['visitor']['expires'] = 60*60*24*30*12
htmlBody.insert(0, 'Content-type: text/html; charset=UTF-8\n')
print(cookie)
print('\n'.join(htmlBody))
=============================
Which i seicth on and off according to my desire if i want to be
counted or not!
How do you know when it _is_ you? There'll be a cookie which says it's
you?
If so, then you want to execute the block if there isn't any cookie, or
if there's a cookie but it doesn't say it's you:
not mycookie or mycookie.value != 'nikos'
i tried this as you suggested:
if ( not mycookie or mycookie.value != 'nikos' ) or re.search( r'(msn|
yandex|13448|spider|crawl)', host ) is None:
but the counter keeps increasing although the cookie named visitor on
my browser exist and also has the valuie of 'nikos'.
Why it keeps increasing? Doesn't the if code "sees" that the cookie
with a value of "nikos" is present!?!!