Cookies

Thread Solved

Join Date: Nov 2008
Posts: 58
Reputation: adam291086 is an unknown quantity at this point 
Solved Threads: 0
adam291086 adam291086 is offline Offline
Junior Poster in Training

Cookies

 
0
  #1
Jan 26th, 2009
I am trying to set a cookie but when i check my browser cookies nothing is set. What am doing wrong

  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\">"
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 58
Reputation: adam291086 is an unknown quantity at this point 
Solved Threads: 0
adam291086 adam291086 is offline Offline
Junior Poster in Training

Re: Cookies

 
0
  #2
Jan 26th, 2009
solved it by just using this line

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

instead of using the cookiee module
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC