Forum Moderators: coopster

Message Too Old, No Replies

Generating Unique User ID for visitor

And write this id to cookie

         

iProgram

9:21 am on Nov 14, 2005 (gmt 0)

10+ Year Member



I want to generate an unique user id for each visior to indetify them, for tracking purpose.

To C++/COM programmers: just like the Microsoft's GUID Gen tool

So what's the best why to generate this unique id?

For example, is the following method reliable?

$user_ip_address = $_SERVER['REMOTE_ADDR'];
$unique_user_id = md5($user_ip_address . timer());
setcookie('user_id', $unique_user_id, ... );
Or is there a better method?

zulu_dude

9:52 am on Nov 14, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



How long do you want the id to be valid for? If it's only per session, then you could just use their session id, which you can get by using (i think) session_id()

If you need the extra security, then you can md5 that with their IP address. But in 99% of cases, just using the session id should suffice.

iProgram

10:14 am on Nov 14, 2005 (gmt 0)

10+ Year Member



>How long do you want the id to be valid for?

1000 years.

>If you need the extra security, then you can md5 that with their IP address.

But the IP address may be changed from time to time. For example, a guy visits my site at Nov 20, 2005. His IP address may be 123.123.123.123. Another guy in the same city visit my site at Nov 21, 2005 and his IP address may be 123.123.123.123 too. Because they are all using dial up ADSL of the same ISP in that city. That's why I add a UNIX timestamp (time()) after IP address.

paperl

11:59 am on Nov 14, 2005 (gmt 0)

10+ Year Member



Remember that cookies are stored on user's computers. This means that if you want to track them, you don't have to assign a unique ID to each of them in order to recognize them when they re-visit. Instead you can just try to read your cookie when they open the website. If you can open the cookie, they visited you before. If not, you create a cookie that you save for 30 years (something like this is the max I think).