-
安裝hashids套件
composer require hashids/hashids
-
加密範例
<?php // encode.php header('Content-Type: text/html; charset=utf-8'); require __DIR__.'/vendor/autoload.php'; use Hashids\Hashids; $hashids = new Hashids(); $dataSn = "33"; $id = $hashids->encode($dataSn); echo '<a href="decode.php?id='.$id.'">查詢</a>';
-
解密範例
<?php // decode.php header('Content-Type: text/html; charset=utf-8'); require __DIR__.'/vendor/autoload.php'; use Hashids\Hashids; use Carbon\Carbon; $hashids = new Hashids(); $dataSn = $_GET['id'];; $id = $hashids->decode($dataSn); echo '接到的變數:'.$dataSn; echo '<hr>'; echo '解密結果為:'.$id;
- 在
php.ini
檔裡設定date.timezone
參數。 - 在開始操作日期或時間之前可以呼叫
date_default_time_zone()
函式來設定。 - 在PHP7,若沒有設定時區預設值的話,PHP預設使用
UTC
時區。