PHP code example of samsonkwiz / idobfuscator

1. Go to this page and download the library: Download samsonkwiz/idobfuscator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

samsonkwiz / idobfuscator example snippets


    

   use SamsonKwiz\IDObfuscator\IDObfuscator;
   

   // Create a new obfuscator instance with default settings
   $obfuscator = new IDObfuscator();

   $originalId = 12345;
   $encoded    = $obfuscator->encode($originalId);   // e.g. "004829374"
   $decoded    = $obfuscator->decode($encoded);     // back to 12345

   echo "ID {$originalId} → {$encoded} → {$decoded}";
   

   $originalId = 54321;
   $encoded    = IDObfuscator::obfuscate($originalId);
   $decoded    = IDObfuscator::deobfuscate($encoded);

   echo "ID {$originalId} → {$encoded} → {$decoded}";
   

   $salt     = '246802468';
   $key      = '13579135';
   $length   = 12;  // exact length of the obfuscated string

   // Create a custom obfuscator
   $customOb = new IDObfuscator($salt, $key, $length);

   $id       = 98765;
   $encoded  = $customOb->encode($id);
   $decoded  = $customOb->decode($encoded);

   echo "Custom ID {$id} → {$encoded} → {$decoded}";
   
bash
composer dump-autoload