exists("tokens:$token")){ break; } } while(1); $redis->set("tokens:$token", 0); // Store the token forever, when set to 1, don't allow token to be used anymore. $_SESSION['token'] = $token; ?>