Giter Site home page Giter Site logo

hashids-example's Introduction

網址Get變數內容做加密,避免使用者略過正常操作直接人工切換網址,取得不該被取得的資料

  • 安裝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 時區。

hashids-example's People

Contributors

hungjung avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.