= 200 & $code <= 299) { if (preg_match('/\(\w+)\<\/authentication\-token\>/i', $body, $matches)) { $token = $matches[1]; } } } # Cleanup cURL curl_close($ch); return $token; } function myplexValidTokens() { global $PLEX_TOKENS_URL; $tokens = array(); $body = @file($PLEX_TOKENS_URL); foreach ($body as $line) { if (preg_match('/\]*)\>/', $line, $matches)) { $attrs = $matches[1]; if (preg_match('/\btoken\=\"(\w+)\"/', $attrs, $matches)) { $tokens[$matches[1]] = 1; } } } return $tokens; } function myplexServerToken($userToken) { global $PLEX_SERVERS_URL; global $PLEX_SERVER_NAME; $token = false; $body = @file($PLEX_SERVERS_URL . $userToken); foreach ($body as $line) { if (preg_match('/\]*)\>/', $line, $matches)) { $attrs = $matches[1]; if (preg_match('/\bname\=\"(\w+)\"/', $attrs, $matches)) { if ($matches[1] == $PLEX_SERVER_NAME) { if (preg_match('/\baccessToken\=\"(\w+)\"/', $attrs, $matches)) { $token = $matches[1]; } } } } } return $token; } function myplexAuthorize($token) { $tokens = myplexValidTokens(); $serverToken = myplexServerToken($token); return ($tokens[$serverToken] ? true : false); } ?>