php - static variable not incrementing on function calling -


function gentokenno() {     static $i=0;     $i=$i+1;     return str_pad($i, 5, '0', str_pad_left); } 

when calls function in other file function doesn't returns unique value (an incremented value). while echo function in same file(where function made) works fine. know concept of scope of static variable have tried replacing $i $_session['i'] no expected result. in advance.

note value of $i not persisted. whenever run new request server, script reloaded , $i reset 0.

to persist variable in per-user session use $session['i'] tried, unique per session, not globally.

to have globally unique number need store on disk, using fopen/flock/fread/fwrite/fclose functions.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -