This question was asked (and answered) quite recently. Have you tried using the search feature of the forum? It is a bit tedious posting the same answer multiple times.
What error messages do you receive? Have you tried using your error console (press F12 key)? Or putting alerts in at strategic positions so you can inspect the values?
You should bear in mind that users may (and often do) delete their cookies - sometimes once a day if they use CCleaner. Also, the dates and number of visits to your site (even if accurate) is visible only to the user himself - not to you.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Last edited by Philip M; 04-08-2013 at 11:37 PM..