Jump to content

Unique ID

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Sometimes you need to create a unique id for something.. i'll show you one really easy way how to create a unique id:

<?php
echo uniqid(); // This will create a ID what is 13 characters long
?>

Example

<?php
echo uniqid('', true); // This will create a ID what is 23 characters long
?>

Example

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
What is each parameter responsible for? Meaning what happens if i change true to false? and what can i put in the ' ' ?

#3
Guest_Jaan_*

Guest_Jaan_*
  • Guests
uniqid syntax is:


uniqid(string prefix, [bool_more_entropy])

so.. if you use this:


<?php

echo uniqid('', true); // This will create a ID what is 23 characters long

?> 


then you can write your ID prefix into ' '.

Example:

<?php

echo uniqid('codecall', true);

?>

This will create a unique id what looks like this:
Check
Like you see there's prefix+id so there have to be codecall(idHere)

Now those true and false statements

If you use false statement then your id will be 13 characters long, but if you use true statements then this id will be 23 characters long