Skip to content

php - create uuid in php

If you need a kind of unique id creation inside php (but can not or do not want to use your database for this job), here is a small function for this. I have also implemented a md5 hash compare. You can replace your current md5 hash method with this one (if you are getting errors in your unittests for e.g. ;-) ).

?php $generatedUUIDs = array(); $generatedMd5s = array();

for($i = 0;$i<10000;$i++) { $generatedUUID = createUUID(); $generatedMd5 = md5($generatedUUID); if (inarray($generatedUUID, $generatedUUIDs)) { echo 'matching same uuid in run ' . $i . PHPEOL; exit(); } else { $generatedUUIDs[] = $generatedUUID; } if (inarray($generatedMd5, $generatedMd5s)) { echo 'matching same md5 in run ' . $i . PHPEOL; exit(); } else { $generatedMd5s[] = $generatedMd5; } } echo 'Run ' . $i . ' creations of UUIDs successfully.' . PHP_EOL;

function createUUID() { return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mtrand(0, 0xffff), mtrand(0, 0xffff), mtrand(0, 0xffff), mtrand(0, 0x0fff) | 0x4000, mtrand(0, 0x3fff) | 0x8000, mtrand(0, 0xffff), mtrand(0, 0xffff), mtrand(0, 0xffff)); }

Translate to de es fr it pt ja

tool.bazzline.net - what a user model should have

Even while i was working on my auth plugin for the zend framework, i tought it is right that the user db table needs to store the password.

Well, bad luck, i was wrong. I wrestled with the fact that the password is stored in my user domain model. This leads to the fact that everywhere where use the user domain model the code can have access to the password - that sucks in the matter of security.

After a few minutes with a colleague we figured out that a password and even the loginname should be stored and managed by an auth class. Even cooler, when you store this information in a central authentification you can use it everywhere (i mean other projects or modules as well).

Translate to de es fr it pt ja

tool - php 5.4

Since the PHP 5.3 update nightmare, i will wait a while before i update my version. But all in all there are three cool features inside, traits, short array syntax and DTrace. Since DTrace is something for "when my development sever is ready to run", short array syntax and traits are ready to use.

Short array syntax is pretty nice.

$foobar = ['foo' => 'bar'];

And traits, well we will see if it is good to use ore not. I like the fact that you can easily define one method and use it where you want. So it is more or less an interface with implementation. I will spare you from the general Singleton example here ;-).

But i can recommend the following links if you want to know more. <a href="https://blogs.oracle.com/netbeansphp/entry/php54supportshort" target="_BLANK" title="short array syntax in php 5.4 and netbeans - 120316>short array syntax Whats new in php 5.4.0 traits Migration from 5.3.x to 5.4.x

Translate to de es fr it pt ja

web - google wtf?

I was astonished that my search results on google are fixed location based. I can change the location inside a country via the name of the city or a zipcode but i can not disable this "feature".

When i tried my search with duckduckgo.com, everything looks as expected.

It is bad to see that also google became what a big company has to became :-(.

Translate to de es fr it pt ja