Jump to content
Sign in to follow this  
WoHe

how to set unique values to each cookie?

Recommended Posts

I was wondering if there is any way to set unique values to each cookie.

 

I want to use these cookies on my website to see if the visitor has already visited my website once, but without asking any information from them.

 

This way I want to store this unique value in my database each time someone opens my website, and I will be able to see if there have been - for example - 20 different visitors in the past month, or if the same person has visited my website 20 times.

 

 

All my code is already written and working, I only need a way to set a different unique value to each cookie I set.

Share this post


Link to post
Share on other sites

A timestamp will give you a unique value unless two users appear at the same second. Get the timestamp by using PHP's time() function.

 

If one second is not precise enough, there's microtime() the gets microsecond precision, pretty much guaranteed to give two users a different value even if they visit the site at the same instant.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...