哪个在facebook popup关闭时更安全?

a quick simple question , my intention is $user run 1st before isset $user , what i am doing isit risky? will it cause any error by possible. so far no problem.

my code

session start();

$user = $facebook->getUser();

if($user){ // i want it to run this script 1st
try{
    $user_profile = $facebook->api('/me');
    $_SESSION['User'] = $user_profile;
}catch(FacebookApiException $f){
    echo '<pre>'.htmlspecialchars(print_r($f, true)).'</pre>';
    $user = null;
}
}

$loginUrl = $facebook->getLoginUrl(array(
'scope'=> 'email,user_education_history',
'display'=>'popup',
));

if(isset($user)){ //this come up after 
    echo "<script>
    window.close();
    window.opener.location.href = 'index.php';
    </script>";
}

Myway: i load and close the window at the same script , with closing the window if $user is set(isset) but will be too risky ??? will it cause any problem ??

Someone way: some one do redirect to other empty page just to close the window , only window.close(); inside ,it looks more safety but seem loading a other page with no reason.

so which one is more safe ???