top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Python: Cookie gets changed when hit comes from a referrer

+1 vote
550 views
# initialize cookie and retrieve cookie from clients browser
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )

if cookie.get('ID') is not None:
 cookieID = cookie['ID'].value
else:
 cookieID = random.randrange(0, 9999)
 cookie['ID'] = cookieID
 cookie['ID']['path'] = '/'
 print( cookie )

I use this code to retrive or set a cookie to the visitor's browser if present and identify him by it.

All work well except the situation where the user visits my webpage by clicking a backlink on another webpage.

Then for some reason the cookieID changes to another value thus a new entry appears into the database when insert happens.

What can I do about that?

posted Oct 8, 2013 by Satish Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
You are aware that using cookies to track a user who doesn't want to be  tracked won't work, because he'll just tell his browser to not use cookies, aren't you.

If a user doesn't want to be tracked, you can't track them. The user controls all the data their machine sends to you. This means that they can manipulate it. Nothing you can do  will prevent this.

1 Answer

+1 vote

The most likely possibility is that the domain doesn't match. For example, the cookie is set for the domain www.foo.com, and the other webpage is linking to foo.com. Another possibility is that the cookie is expiring because the browser session was terminated, not because of anything to do with the other webpage.

Or it could simply be a bug or unusual setting in whatever browser you're using to test it.

answer Oct 8, 2013 by anonymous
I think this is the problem but i am not sure entirely how you mean. Can you please explain it a bit more?

Shall i change cookie['ID']['path'] = '/' to something else so that never happens?
Similar Questions
+1 vote

I use apache 2.4 on centos.

I want to protect the access to a page (/my_folder/secure) with a cookie (in my exemple the cookie name is : my_cookie_name)

I would like that some machine with IP 192.1.1.10 and 192.1.1.11 can access the server without the cookie. This two IP address don't need to have the cookie for access to /my_folder/secure)

And all other IP address are redirect to address https://my_register_site.com if they don't have the cookie.

How to write this ? Some example, and of course it does not work.

Session On 
RewriteEngine on 
RewriteCond %{HTTP_COOKIE} !my_cookie_name 
RewriteCond %{REMOTE_ADDR} !^192.1.1.10$ 
RewriteCond %{REMOTE_ADDR} !^192.1.1.11$ 
RewriteRule ^(.*)$ https://my_register_site.com [NC,L,R=301] 
+1 vote

I'm trying to figure out how I can create custom session cookies. I've found the Manager interface for creating the sessions, but there's nothing about the actual session cookie. I don't see anything in the Valve interface that will let me do this either. Is this possible in Tomcat 7 (or 8?).

+3 votes

I just updated this morning my Python from a 3.3rc to 3.4 (Windows) and I noticed that the 'Green' color in tkinter GUI is not the same at all.

'Green' in 3.4 is very dark. I had to replace it with 'Lime' to get back a nice 'Green'.

...