aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tools/Utils.php
blob: 7e2968e77f45153fc55178fd9bac190450a7bb5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

namespace Wallabag\CoreBundle\Tools;

class Utils
{
    /**
     * Generate a token used for RSS.
     *
     * @return string
     */
    public static function generateToken()
    {
        if (ini_get('open_basedir') === '') {
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                // alternative to /dev/urandom for Windows
                $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
            } else {
                $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
            }
        } else {
            $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
        }

        // remove character which can broken the url
        return str_replace(array('+', '/'), '', $token);
    }
}