ki Posted September 27, 2012 Share Posted September 27, 2012 I'm not asking for any code really. I need a way to create a unique UserID per $_SESSION or by md5 hashing their IP address and only using the first 6 or 7 characters. Does anyone have any ideas into this? I'm not requiring a login for my specific project, but do want individuals posting to recognize each other within some time period or sense. Quote Link to comment https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/ Share on other sites More sharing options...
White_Lily Posted September 27, 2012 Share Posted September 27, 2012 (edited) simple, go into your MySQL database, add a column at the beggining of your requested table, name it "UserID" or whatever. Then all you have to do is add this to your sessions: $id = $_SESSION["UserID"]; Create the column with an index of "PRIMARY" and A-I to "Yes" (or in my case just click the small box). Edited September 27, 2012 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/#findComment-1381425 Share on other sites More sharing options...
ki Posted September 27, 2012 Author Share Posted September 27, 2012 I mean, I'm trying to use their unique name for posting, I just dont know which method to approach this at. Quote Link to comment https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/#findComment-1381426 Share on other sites More sharing options...
White_Lily Posted September 27, 2012 Share Posted September 27, 2012 then in such case where you want their name/username to appear you need something along the lines of this: echo "<p>".$_SESSION["username"]."</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/#findComment-1381427 Share on other sites More sharing options...
DavidAM Posted September 27, 2012 Share Posted September 27, 2012 Hashing does not guarantee uniqueness, and is not designed to provide unique results. I think I would avoid that. Are you looking for anything in particular, as far as characters go? The uniqid() function will provide a unique value, mostly. It is based on the underlying server's timestamp (in milliseconds). Here are a few from my system generated in a loop, one right after the other. 5064d63e03753 5064d63e03789 5064d63e037bf 5064d63e037f6 5064d63e0382c 5064d63e03863 5064d63e03899 Quote Link to comment https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/#findComment-1381434 Share on other sites More sharing options...
xyph Posted September 27, 2012 Share Posted September 27, 2012 I think he wants the token to stay consistent over multiple requests. I don't think using the session ID is a good idea, even if obfuscated or hashed. Your best bet is to generate a string based on random data, then store this in a cookie with a FALSE expiration, so it expires with the user. We'd need more details to give you a better solution Quote Link to comment https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/#findComment-1381446 Share on other sites More sharing options...
ki Posted September 28, 2012 Author Share Posted September 28, 2012 Hashing does not guarantee uniqueness, and is not designed to provide unique results. I think I would avoid that. Are you looking for anything in particular, as far as characters go? The uniqid() function will provide a unique value, mostly. It is based on the underlying server's timestamp (in milliseconds). Here are a few from my system generated in a loop, one right after the other. 5064d63e03753 5064d63e03789 5064d63e037bf 5064d63e037f6 5064d63e0382c 5064d63e03863 5064d63e03899 I kind of like this but I want it kind of like 4qR31~ Something like that, just an example though. I think I would have to use a session though. I think he wants the token to stay consistent over multiple requests. I don't think using the session ID is a good idea, even if obfuscated or hashed. Your best bet is to generate a string based on random data, then store this in a cookie with a FALSE expiration, so it expires with the user. We'd need more details to give you a better solution How would I go about doing this one? Someone could potentially edit that cookie and edit their ID appearing as someone else though. Quote Link to comment https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/#findComment-1381460 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Share Posted September 28, 2012 If you decide to go with the cookie suggestion, read up on cookie laws - you will have to include somewhere on your page that you use cookies, also specify what the cookie(s) is and are doing. Quote Link to comment https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/#findComment-1381461 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.