0

I'm trying to create an API which generate guid. My php work perfectly on windows with wampp but it doesn't work on apache2 on my ubuntu server...

What's wrong?

$key = 0;

    if (function_exists('com_create_guid')){
        $key = trim(com_create_guid(), "{}");
    }else{
        mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);// "-"
        $key = substr($charid, 0, 8).$hyphen
            .substr($charid, 8, 4).$hyphen
            .substr($charid,12, 4).$hyphen
            .substr($charid,16, 4).$hyphen
            .substr($charid,20,12);
    }

    $mail = $_GET['mail'];
    $nom = $_GET['nom'];
    $prenom = $_GET['prenom'];

    if($mail && $nom && $prenom){
        $retour = sendMail($mail, $nom, $key);
    }else{
        $retour = false;
    }

EDIT:

I need use this:

bin2hex(openssl_random_pseudo_bytes(16));

This isn't the same format but it works!

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Guillaume
  • 108
  • 10
  • and you mirrored the server completely (in terms of php version/modules etc.) – treyBake Jul 10 '19 at 16:00
  • Pretty sure COM is only ever going to work on Windows. Sort of like why does the .DLL not work on Ubuntu... Yup... https://www.php.net/manual/en/com.requirements.php – ficuscr Jul 10 '19 at 16:01
  • Workarounds are discussed in the answers here: [How to generate a new GUID?](https://stackoverflow.com/questions/21671179/how-to-generate-a-new-guid) Maybe close this as a dupe of this question? – ficuscr Jul 10 '19 at 16:03
  • 3
    Possible duplicate of [How to generate a new GUID?](https://stackoverflow.com/questions/21671179/how-to-generate-a-new-guid) – Dave Jul 10 '19 at 16:05
  • My PHP vesion is 7.2.19 on ubuntu and 7.2.14 on windows – Guillaume Jul 10 '19 at 16:07
  • 1
    @Guillaume again, "COM functions are only available for the Windows version of PHP." Follow the recommended links... – ficuscr Jul 10 '19 at 16:07
  • It's duplicate but the answer indicated on the other post is false – Guillaume Jul 10 '19 at 16:17
  • @Guillaume what do you mean the answer is false? Looking at the accepted answer with the `function_exists` check? – ficuscr Jul 10 '19 at 16:46

0 Answers0