PHP - 如果在if内

So I am trying to run some PHP code if the URL exactly matches whatever I specify...if the url doesn't match this it should do nothing. However if it does match the url, I want to run another statement to check if the user is logged in...if they are it should do nothing. If they are not it should redirect them. I have written some code for this but it doesn't seem to be working...any ideas?

Code is here:

$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'example.com') 
{
    //User is on main page
    if ( is_user_logged_in() ) {
       //Do nothing
        } else {
       header("Location: https://example.com/welcome");
        }
} else {/*do nothing*/}

Try this

$host = $_SERVER['SERVER_NAME'];
if($host == 'example.com' && !is_user_logged_in()) 
{
   header("Location: https://example.com/welcome");

} else {/*do nothing*/}