943,740 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 608
  • Python RSS
Jan 26th, 2009
0

Cookies

Expand Post »
I am trying to set a cookie but when i check my browser cookies nothing is set. What am doing wrong

Python Syntax (Toggle Plain Text)
  1.  
  2. #!/usr/bin/python
  3. # e begoli, python connector for mysql
  4. # import MySQL module
  5. import MySQLdb
  6. import cgi
  7. import Cookie
  8. import time
  9. cookie = Cookie.SimpleCookie()
  10. cookie["ID"] = ""
  11. print "Content-type: text/html\n"
  12.  
  13. # connection
  14. db = MySQLdb.connect(host = "dsfdsfdsfsdf", user = "sdfsdfsdfsdf", passwd = "sdfsdfsdfdsfds", db = "dsfdsfdsfdsf")
  15.  
  16. form = cgi.FieldStorage()
  17. if form.has_key("username")and form["username"].value !="" and form.has_key("password") and form["password"].value !="":
  18. username = form["username"].value
  19. password = form["password"].value
  20.  
  21. # create a database cursor
  22. cursor = db.cursor(MySQLdb.cursors.DictCursor)
  23.  
  24.  
  25. # execute SQL select statement
  26. cursor.execute("SELECT * FROM User WHERE UserName = username AND Password = PASSWORD('"+password+"')")
  27.  
  28. # get the number of rows in the resultset
  29. numrows = int(cursor.rowcount)
  30.  
  31. if numrows ==0:
  32. print "<meta http-equiv=\"refresh\" content=\"0;url=http://adamplowman.com/uni_project/login.html\">"
  33. else:
  34. Results = cursor.fetchall()
  35. for subelement in Results[0].keys():
  36. if subelement == "Id":
  37. ID = int(Results[0][subelement])
  38.  
  39. # get the number of rows in the resultset
  40. numrows = int(cursor.rowcount)
  41. cookie["ID"] = ID
  42. print "<meta http-equiv=\"refresh\" content=\"0;url=http://adamplowman.com/uni_project/main.html\">"
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
adam291086 is offline Offline
61 posts
since Nov 2008
Jan 26th, 2009
0

Re: Cookies

solved it by just using this line

print 'Set-Cookie: lastvisit=' + str(time.time());

instead of using the cookiee module
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
adam291086 is offline Offline
61 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Dictionary Looping Name Error
Next Thread in Python Forum Timeline: Error: "TypeError: argument of type 'int' is not iterable"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC