<?php
// Generates a random GUID per http://www.ietf.org/rfc/rfc4122.txt
function genGUID () {
   
//e.g. output: 372472a2-d557-4630-bc7d-bae54c934da1
   //word*2-, word-, (w)ord-, (w)ord-, word*3
   
$guidstr "";
   for (
$i=1;$i<=16;$i++) {
      
$b = (int)rand(0,0xff);
      if (
$i == 7) { $b &= 0x0f$b |= 0x40; } // version 4 (random)
      
if ($i == 9) { $b &= 0x3f$b |= 0x80; } // variant
      
$guidstr .= sprintf("%02s"base_convert($b,10,16));
      if (
$i == || $i == || $i == || $i == 10) { $guidstr .= '-'; }
   }
   return 
$guidstr;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>GUID Generator</title>
<meta http-equiv="pragma" content="no-cache" />
<style type="text/css">
<!--
body, h1 {
   font-family: verdana, sans-serif;
}
pre { font-family: courier, monospace; font-size: larger; font-weight: bold; }
input, select { background-color: gold; }
abbr { cursor: help }
-->
</style>
</head>
<body>

<h1>GUID Generator</h1>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="submit" value="Generate" />
<select name="nguid">
<?php
$guidopts 
= array (1,10,25,50,100,250,500);
//$nguid=(int)$_GET['nguid'];
$nguid = isset($_REQUEST['nguid']) ? (int)$_REQUEST['nguid'] : 1;
if (
$nguid || $nguid $guidopts[count($guidopts)-1]) { $nguid=1; }
foreach (
$guidopts as $k) {
   echo 
"<option value=\"$k\"" . (($k==$nguid)?" selected=\"selected\"":"") . ">$k</option>\n";
}
?>
</select>
Random <abbr title="Globally Unique IDentifier">GUID</abbr>s
</form>

<pre>
<?php
while ($nguid--) {
   
//echo '{' . strtoupper(genGUID()) . '}' . "\n";
   
echo genGUID() . "\n";
}
?>
</pre>

<br />
<br />
<small>
<a href="http://www.ietf.org/rfc/rfc4122.txt">rfc4122</a><br />
<?php if(file_exists($_SERVER['SCRIPT_FILENAME'].'s')){echo '<a href="' $_SERVER['PHP_SELF'] . 's">View source</a>';} ?>
</small>


</body>
</html>