In my PHP project I created a singletone class that mange my access tokens.
The tokens are some constant strings with timestamp of +/- 5 min hashed with SHA1.
I want that each page can access to this singletone instance (the same instance) because it holds the tokens. Also there going to be a procedure that refresh the tokens in that instance.
The name TokenManager with located in different php file.
I create the instance $TOKENS in different file.
<?php require_once 'TokenManager.php'; $TOKENS = TokenManager::Instance(); And another file for refresh action (refreshTokens.php):
<?php require_once 'Tokens.php'; global $TOKENS; $TOKENS->refreshTokens(); var_dump($TOKENS->tokens); In another page that is a web service (AddUser) I use the this Tokens.php instance as global.
require_once 'TokenManager.php'; require_once 'Tokens.php'; ................................... function start(){ global $userParams; global $TOKENS; //Check for all mandatory params if(!ValidateParams()){ finish(); } if(!$TOKENS->checkTokenAndGetChannel($userParams[PARAM_TOKEN])){ setError(ERR6_BAD_TOKEN, CODE6_DESC); finish(); } if(!isEmailValidByDrupal($userParams[PARAM_EMAIL])){ setError(ERR3_BAD_EMAIL, CODE3_DESC . $userParams[PARAM_EMAIL]); finish(); } finish(); } The problem that each time I call refreshTokens.php and take the token I have each time new instance with a different values what makes the tokens each time invalid.
What can I do about that?