3
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UUID

Last updated at Posted at 2017-02-18

###uniqid

  • 「uniqid」は、13桁のIDが生成。
  • 100万分の1の単位で、同じIDが生成されてしまう可能性がある。

<?php
echo uniqid() .'<br>';
57973297df893
57973297df962
  • リロードするたびに上記のように生成される
  • 13文字

####uniqidで第2引数にtrueを指定


<?php
echo uniqid('',true) .'<br>';
57973a133a4078.27426087
  • 第2引数にtrueを指定するとより推測の難しいユニークな文字列を生成する
  • 23文字

###md5()

  • md5ハッシュ値を計算

$text = 'abcde12345';
$text2 = 'abcde12345';

echo '<p>'. md5($text).'</p>';
echo '<p>'. md5($text2).'</p>';

df6f58808ebfd3e609c234cf2283a989
df6f58808ebfd3e609c234cf2283a989

  • リロードしても同じ値が生成される

#md5ハッシュとuniqidとを組み合わせる(32桁のユニークIDを生成)


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>ユニークなIDを作成したい</title>
</head>
<body>
<div>
<?php
echo md5(uniqid(mt_rand(), true)) .'<br>';
?>
</div>
</body>
</html>
  • 32桁

3c9aa5b706cfc18e231d9f455cdf6e27
1954a51a41a54a2845dceecf6ded1f88

#UUID as id with laravel

3
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?