duanliangman5398 2014-03-11 14:50
浏览 19

检查此方法是否适用于唯一ID

I'm trying to create ids to diversified contents using md5 to encode but, I'm not sure about this method.

<?php    
$prefix = 'stackoverflow';
$length = 11;
$id = md5( $prefix . uniqid(microtime()) );

$part1 = substr($id, 0,(floor($length / 2))); //First 5 chars

$id = strrev($id); //Reverse md5

$part2 = substr($id, 0,(ceil($length / 2))); //First 6 chars of the reversed md5

$final_id = $part2 . $part1; //Reverse final id
?>
  • 写回答

2条回答 默认 最新

  • douming4359 2014-03-11 14:53
    关注

    You're trying to reinvent a wheel.

    http://www.php.net/manual/en/function.uniqid.php

    string uniqid ([ string $prefix = "" [, bool $more_entropy = false ]] )

    Gets a prefixed unique identifier based on the current time in microseconds.

    Also you might want to use real globally unique identifiers (windows specific extension)

    http://www.php.net/manual/en/function.com-create-guid.php

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改