我需要一个 php 函数来生成访问 token 以唯一标识用户。我会将此 token 存储在一个名为“ token ”的额外列中,我将使用它对移动应用程序进行身份验证。我在网上搜索了它,所有结果都指的是推特或 Facebook 。我的应用中需要它。
我使用 cakePHP 后端和 Android 平台。
非常感谢。
最佳答案
使用 guid :-
function getGUID(){
if (function_exists('com_create_guid')){
return com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}
}
$GUID = getGUID();
echo $GUID;
或引用此链接 http://guid.us/GUID/PHP
关于php - 生成用于 Web 服务身份验证的访问 token 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14581983/