-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
73 lines (65 loc) · 1.75 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
require_once('guid.class.php');
/* make it short */
use OZ\GUID as GUID;
/* SCHEMA - data schema of your guid, see README or guid.class.php for more instructions */
$GUID_schema = array(
'type' => 2,
'field1' => 4,
'field2' => 4,
'field3' => 4,
'flags1' => 1,
'flags2' => 1
);
/* KEY - your secret md5() hash */
$GUID_key = '7116bfe60a4d7393b2151400ef3a67ea';
if(GUID::init($GUID_schema, $GUID_key)) {
/* some date */
$data = array(
'type' => 1,
'field1' => 123,
'field2' => 12,
'field3' => 1,
'flags1' => 0, /* 0000 */
'flags2' => 6 /* 0111 */
);
/* data > guid */
echo 'Data to GUID: <br/>';
$guid1 = GUID::code($data);
print_r($data);
echo ' > ' . $guid1;
echo '<br/>';
$data['flags2'] = 5; /* 0110, change data for 1 BIN digit */
$guid2 = GUID::code($data);
print_r($data);
echo ' > ' . $guid2;
echo '<br/>';
echo '<br/>';
echo 'GUID to data: <br/>';
echo $guid1 . ' > ';
print_r(GUID::decode($guid1));
echo '<br/>';
echo $guid2 . ' > ';
print_r(GUID::decode($guid2));
echo '<br/>';
echo '<br/>';
echo 'Fake GUID to data: <br/>';
$guid3 = '7a368ea2-2eeb-851a-1258-f5dd806f7a08'; /* change last HEX digit */
$data3 = GUID::decode($guid3);
echo $guid3 . ' > ';
print_r(empty($data3) ? 'false' : $data3);
echo '<br/>';
$guid3 = '7a368ea2-2eeb-851a-2258-f5dd806f7a09'; /* change one middle HEX digit */
$data3 = GUID::decode($guid3);
echo $guid3 . ' > ';
print_r(empty($data3) ? 'false' : $data3);
echo '<br/>';
$guid3 = '7a368ea2-2eec-851a-1258-f5dd806f7a09'; /* change one middle HEX digit */
$data3 = GUID::decode($guid3);
echo $guid3 . ' > ';
print_r(empty($data3) ? 'false' : $data3);
echo '<br/>';
}
else {
echo 'GUID class is not init';
}