Unique user ID

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
Dedicated Kid
Forum Newbie
Posts: 3
Joined: Sat Sep 25, 2010 6:42 am

Unique user ID

Post by Dedicated Kid »

hi i am building a site where people will log in and get access to there user area.

they will have to register first and i was thinking about using the session id that they had to register with as their unique user id is this a sound idea or just maddness.

my thinking is that all session id's should be unique as they are generated from the system time.

if this is not a good idea does anyone have any ideas how i can generate a unique user id?

Thanks all
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Unique user ID

Post by John Cartwright »

You would generally use an auto incremented id in your users table to serve as their "unique id".
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Unique user ID

Post by DigitalMind »

John Cartwright wrote:You would generally use an auto incremented id in your users table to serve as their "unique id".
think so too
Monotoko
Forum Commoner
Posts: 64
Joined: Fri Oct 26, 2007 4:24 pm

Re: Unique user ID

Post by Monotoko »

In order to make it auto increment you will need to select it as your Primary Key or it will throw an error. I took an hour trying to figure that out to start with ;P
amplifire
Forum Newbie
Posts: 23
Joined: Thu Jul 22, 2010 1:09 am
Location: India
Contact:

Re: Unique user ID

Post by amplifire »

Hi dedicated kid!

lets see what wee can do. If you want to generate a unique id (I think you want your users to have different IDs).
1)Ok first of all you would have to save your users IDs in database.
2)Whenever your people create a new user, it should be checked in the database, IF the ID already exists it should not be Inserted into Database. ELSE IF the ID is not created, it can be inserted into Database Table.
For this create a connection and fill up an array, if it gets filled up, it means database has entry of same ID, otherwise its an new entry.

Ex:
$db = mysql_connect( "localhost", "root", "" );
mysql_select_db( "myTable", $db )

$sql='SELECT * FROM myTable';
$result=mysql_query($sql,$db);
$rows=mysql_fetch_array(result);
Post Reply