PHP生成唯一ID uniqid()方法

动态 2018-12-27 01:34:31
432

官方uniqid()参考手册有用户提供的方法,结果类似:{E2DFFFB3-571E-6CFC-4B5C-9FEDAAF2EFD7}.

public function create_guid($namespace = '') {

static $guid = '';

$uid = uniqid("", true);

data=data=namespace;

data.=data.=_SERVER['REQUEST_TIME'];

data.=data.=_SERVER['HTTP_USER_AGENT'];

data.=data.=_SERVER['LOCAL_ADDR'];

data.=data.=_SERVER['LOCAL_PORT'];

data.=data.=_SERVER['REMOTE_ADDR'];

data.=data.=_SERVER['REMOTE_PORT'];

hash=strtoupper(hash(′ripemd128′,hash=strtoupper(hash(′ripemd128′,uid . guid.md5(guid.md5(data)));

$guid = '{' .

substr($hash, 0, 8) .

'-' .

substr($hash, 8, 4) .

'-' .

substr($hash, 12, 4) .

'-' .

substr($hash, 16, 4) .

'-' .

substr($hash, 20, 12) .

'}';

return $guid;

}

回帖
本周热议