added _SERVER['SERVER_PORT'] in URL and check if not empty _SERVER['HTTPS']