0%
savoir image

PHP propose la fonction uniqid pour générer des identifiants uniques. Préfixe à ajouter à l'identifiant. Mettre une chaîne vide ou ne rien mettre si vous ne souhaitez pas de préfixe.

<?php

public function createGUID(){
     // append the IP address w/o periods to the front of the unique ID
     if(isset($_SERVER['REMOTE_ADDR'])){
          $ip = $_SERVER['REMOTE_ADDR'];
     } else{
          $ip = '';
     }
     $varGUID = strtoupper(str_replace('.', '', uniqid($ip, TRUE)));
     $varGUID = str_replace('::','_',$varGUID);
     // add "-"
     // AC041D36-43E8-414E-BD05-F733BCD7298E
     $varGUID = substr($varGUID,0,8).'-'.substr($varGUID,8,4).'-'.substr($varGUID,12,4).'-'.substr($varGUID,16,4).'-'.substr($varGUID,20,12);

     // return the GUID as the function value
     return $varGUID;
}

?>
0 commentaires