Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/268860-creating-a-unique-userid/
Share on other sites

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 by White_Lily

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 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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.