I am planning on creating my database table for users of an offline site that use as a kiosk.. Those kiosk are not conn开发者_如何学编程ected on a network nor to each other, they have a separate webserver and database.. what Is the best thing that I can use to have these users on every kiosk to have their different unique id? I am planning using hash so that when we combine all the data's in every machine on single server we can accommodate each unique ids.
If you have total control over how the IDs will be formed, you can give each machine a unique ID when first setting up, then you can include that data in the user's unique ID so they won't be overlap between machines.
If you don't want to have to do any manual setup, you use some sort of hardware ID (like the network adaptors MAC address) as the machine's unique ID.
I would use PHP's uniqid()
function, or MySQL's UUID()
function.
Use a simple ini file to store the kiosk id and put in front of any unique hash.
It could be implemented in this way:
$config = parse_ini_file('./config.php');
$hash = $config['kiosk_id'].'_'.microtime();
//$hash = md5($hash); //looks more random, but can collide
If you need a zero-setup option, take microtime()
when the user is created, convert it to a string, and then hash that (with md5 or some such)? That should most likely give you uniques for all users, both due to the precision and also the arbitrary variation in the machines' clocks.
If you can do some pre-setup, give each machine a unique ID and have it make a hash from that + some item of user-specific data on the machine.
Your best bet is creating a composite key, based on a regular auto_increment column as the varying part, and an unvarying unique per-kiosk identifer. Hostname, IP address, MAC address if it has an ethernet card (even if not actually in use), Windows SID, etc...
CREATE TABLE user
user_id auto_increment not null,
kiosk_id char(32) not null,
PRIMARY KEY (user_id, kiosk_id),
etc...
);
which can then be trivially combined in a master table later.
精彩评论