View Full Version : Question regarding cookies please.

05-26-2011, 04:49 PM
ow does the code get the visitor's name? Say you [John Doe] visited my website and I wish to place a cookie on your pc if you don't have to fill out a form on my site then how will I know what your name is to place in the setcookie function?

05-26-2011, 04:59 PM
Unless the user provides you some sort of data about who they specifically are, you can't store it. By visiting your site, the user gives you data like IP, browser, and OS... but that's obviously not what you're looking for. Unless they have some some technique of identifying themselves, such as a login, an already existent cookie you have access to, etc, you can't know who they are.

05-26-2011, 05:21 PM
So to clarify, cookies only works if the you have some user form or login? is this correct?

05-26-2011, 07:03 PM
You will need a form yes. Initially you'll have to ask the user their name. There is no way to 'just know it'.

Once you have their name remember to set the cookie before any html or whitespace is output. Cookies are set in the http headers so you must do this before ANYTHING goes to the browser.