php - Static variable is sometimes not storing correctly -


i'm using php generate nonce (unique key) content security policy on site. idea nonce generated first time requested, nonce returned each time after (within single http request). code i'm using

class csp {   private static $nonce = null;    public static function nonce () {     if (!isset(self::$nonce)) {       self::$nonce = bin2hex(openssl_random_pseudo_bytes(15));     }     return self::$nonce;   } } 

it's being called by

\namespace\csp::nonce(); 

the function called several times on each request, , returns different values. example, function called both while sending http headers , while generating page body content, , (probably more 1 in 20 times), different value being sent in http header , in body of response, triggering content security policy (so bad things happening).

also, unrelated, when tried use static:: rather self::, unable set variable. can't find documentation on this, i'm not sure whether it's feature or not.

i'm using php 5.6.9 on apache 2.4.10, running on debian.


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -