Generating Private, Unique, Secure URLs

后端 未结 7 1576
萌比男神i
萌比男神i 2021-01-31 22:06

I\'d like to generate a secure one-click-access type of url similar to the examples below. I\'ll be using PHP but that is irrelevant as I\'m just looking to understand the under

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 22:44

    Try uniqid - and perhaps combine with an md5 hash, as given in the examples:

    // no prefix
    // works only in PHP 5 and later versions
    $token = md5(uniqid());
    
    // better, difficult to guess
    $better_token = md5(uniqid(rand(), true));
    

    I must note however that no urls generated in this way (whatever the hash algorithm) will be 'secure', simply very difficult to guess.

提交回复
热议问题