/** * Creates a random token string that can be used to track a single * email delivery. The returned token string will only contain * lowercase alphanumeric characters and will start with a lowercase * letter to avoid problems with special processing being triggered * by special characters in the token string. * * @return random token string */ private function _create_email_token() { //Testers need dummy token if ($this->test_mode) { return 'dummy'; } //Use mt_rand if possible (faster, more random) if (function_exists('mt_rand')) { $rand = 'mt_rand'; } else { $rand = 'rand'; } $tokenchars = 'abcdefghijklmnopqrstuvwxyz0123456789'; $token = $tokenchars[$rand(0, strlen($tokenchars) - 11)]; for ($i = 1; $i < $this->token_size; $i++) { $token .= $tokenchars[$rand(0, strlen($tokenchars) - 1)]; } //If token is not free or (very, very unlikely) matches our dummy token, recurse. if (!org_openpsa_directmarketing_campaign_messagereceipt_dba::token_is_free($token) || $token === 'dummy') { return $this->_create_email_token(); } return $token; }