I discovered what the issue is. The is_user_logged_in() function checks cookies. WordPress redirected request to wordpress into http://www.the_domain, whereas to access my code I was doing the_domain, without the www. Because there was no www, the cookie origins did not match.