Recent Posts

This Post Has Been Viewed 244 Times.

MD5 Function and Unique ID in php

Posted by admin | Posted in C sharp interview questions, Interview Tips & Tricks, J2ee Interview Questions, PHP, Tools, scripts | Posted on 03-04-2009

0

uniqid () function, This function has two parameters we can set. The first is the prefix. This is what will be appended to the beginning of each ID. The second is more_entropy. If this is false or not specified it will return 13 characters, if it is true then 23 characters will be returned.Uniqid (prefix, more_entropy)Sample Code Very Simple To Use

<?php 

echo ‘creates a unique id with the about prefix<br>’;

$a = uniqid(about);

echo $a;

echo “<hr>”;

echo ‘creates a longer unique id with the about prefix<br>’;

$b = uniqid (about, true);

echo $b;

echo “<hr>”;

echo ‘creates a unique ID with a random number as a prefix - more secure than a static prefix<br>’;

$c = uniqid (rand (),true);

echo $c;

echo “<hr>”;

echo ‘this md5 encrypts the username from above, so its ready to be stored in your database<br>’;

$md5 = md5($c);

echo $md5;

?>

 If you want a unique id then use uniqidThe id’s generated are only unique they are not completely random.If you want completly random id’s then you will need to make your own function, as an md5 or sha1 will not help. As these will provide you with a fixed length string. You could chop an md5 string at a random position, but then you would need to check that this string is unique and not just random 

VN:F [1.5.7_846]
Rating: 0.0/10 (0 votes cast)
VN:F [1.5.7_846]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • Xerpi

Related posts:

  1. “Header already sent” in php error and other use of Header function in PHP
  2. Water mark images using PHP 5 and GD Library

Write a comment

Spam Protected