1. Go to this page and download the library: Download mfonte/base62x 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/ */
mfonte / base62x example snippets
use Mfonte\Base62x\Base62x;
$string = 'this is some string that needs to be encoded';
$encoded = Base62x::encode($string)->get();
$decoded = Base62x::decode($encoded)->get();
// create an ajaxToken to be de('secure_ajax_token')->encrypt(config('app.key'))->compress()->get();
// create a context of data to be passed to the Ajax worker
$contextData = ['route' => 'homepage', 'pagination' => ['currPage' => 1, 'maxPages' => 2]];
$encryptedContextData = Base62x::encode($contextData)->encrypt(config('app.key'))->compress()->get();
$html = <<<EOT
<head>
<meta charset="utf-8">
...
...
<script type="text/javascript">
const ajaxConfig = {
url: 'https://www.example.com/ajaxRequest',
token: '$encryptedAjaxToken',
context: '$encryptedContextData'
};
function ajaxRequest() {
$.post(ajaxConfig.url, Object.assign({
method: "whatever",
}, ajaxConfig)).done(function(response) {
// logic
});
}
</script>
</head>
EOT;
use Mfonte\Base62x\Base62x;
use GuzzleHttp\Client;
// on one machine
$payload = file_get_contents('a_nice_image.jpg');
$encoded_payload = Base62x::encode($payload)->get();
$client = new Client(['base_uri' => 'https://example.com/']);
$response = $client->post('postRequest/', [
'form_params' => [
'encoded_image' => $encoded_payload
]
]);
...
// on another machine
$encoded_payload = $request->get('encoded_image');
$image = Base62x::decode($encoded_payload)->get();
file_put_contents($image, 'a_nice_image_clone.jpg');
use Mfonte\Base62x\Base62x;
$payload = ['foo' => 'bar', 'bar' => ['foo1', 'foo2', 'foo3', 'fooman' => 'foobar'], 'barfoo' => [1,2,3,4,5,6,7,8,9,10]];
try {
$encoded_payload = Base62x::encode($payload)->compress()->get();
}
catch(Exception $ex) {
// One Exception of Mfonte/Base62x/Exception/EncodeException
// or Mfonte/Base62x/Exception/InvalidParam
// or Mfonte/Base62x/Exception/CompressionException
}
$final_url = 'https://example.com/decodetest/?data=' . $encoded_payload;
...
// on the "decodetest" url ...
$encoded_payload = (array_key_exists('data', $_GET) && strlen($_GET['data'])) ? $_GET['data'] : null;
if(!empty($encoded_payload)) {
try {
// in the $decoded variable, you'll automagically get the original Array
$decoded = Base62x::decode($encoded_payload)->get();
}
catch(Exception $ex) {
// One Exception of Mfonte/Base62x/Exception/DecodeException or Mfonte/Base62x/Exception/InvalidParam
}
}
use Mfonte\Base62x\Base62x;
$payload = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
try {
$gzip_default = Base62x::encode($payload)->compress()->get(); // alias of compress('gzip', 'gzip')
$gzip_gzip_encoded = Base62x::encode($payload)->compress('gzip', 'gzip')->get();
$gzip_zlib_encoded = Base62x::encode($payload)->compress('gzip', 'zlib')->get();
$gzip_deflate_encoded = Base62x::encode($payload)->compress('gzip', 'deflate')->get();
// you DON'T NEED to call decompress() because the compression method is "saved" inside the
// encoded payload into a "magic string"
$decoded = Base62x::decode($gzip_default)->get();
}
catch(Exception $ex) {
// One Exception of Mfonte/Base62x/Exception/EncodeException
// or Mfonte/Base62x/Exception/InvalidParam
// or Mfonte/Base62x/Exception/CompressionException
}
use Mfonte\Base62x\Base62x;
$payload = 'my_payload';
$key = 'a_very_secret_string';
try {
$encoded_and_crypted = Base62x::encode($payload)->encrypt($key)->get();
$encoded_and_compressed_and_crypted = Base62x::encode($payload)->encrypt($key)->compress()->get();
// to perform decryption, you must pass in the original $key
$decrypted = Base62x::decode($payload)->decrypt($key)->get();
}
catch(Exception $ex) {
// One Exception of Mfonte/Base62x/Exception/EncodeException
// or Mfonte/Base62x/Exception/InvalidParam
// or Mfonte/Base62x/Exception/CompressionException
// or Mfonte/Base62x/Exception/CryptException
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.