Code Monkey home page Code Monkey logo

php-uuid's Introduction

php-uuid

Random and Pseudo-Random UUIDs

Generate RFC4122 Version 4 (random) UUIDs.

uuid() can return "not really random" UUIDs which - however - don't follow the rules of other types in RFC4122:

define ('UUID_MODE_RANDOM',             0);
define ('UUID_MODE_TIMED',              1);
define ('UUID_MODE_TYPED',              2);
define ('UUID_MODE_USE_REMOTE_ADDR',    4);


$u = uuid(UUID_MODE_TIMED);

Will include the unix timestamp (ms) in the first 8 octets - however in another order than specified in the RFC. RFC starts with least significant bytes, this function starts with highes significant bytes, resulting in "always increasing" ids. That means they will appear in the order created when inserted into database.

$u = uuid(UUID_MODE_TYPED, $type);

Will overwrite the first 2 hex octets with the value specified in $type (value between 0 and 255).

$u = uuid(UUID_MODE_USE_REMOTE_ADDR);

Will put the remote addess ($_SERVER['REMOTE_ADDR'] - IPv4 address) into the "node" part of the UUID: 00000000-0000-0000-0000-111111110000

Feel free to combine the flags

$u = uuid(UUID_MODE_TIMED | UUID_MODE_USE_REMOTE_ADDR);

Will return a uuid with both timestamp and remote address in the UUID;

$u = str2uuid('hello there');

Uses a sha1 checksum to return a UUID. Will always be the same for the same string.

if (!is_uuid($u)) {
    echo 'something is wrong';
} 

Test if a string is formatted like an UUID.

php-uuid's People

Contributors

blam avatar

Stargazers

Threath avatar

Watchers

 avatar James Cloos avatar

php-uuid's Issues

ip2val()

Fatal error: Uncaught Error: Call to undefined function ip2val()

ip2val() function is missing dedicated for UUID_MODE_USE_REMOTE_ADDR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.