title: redirected php page doesn't load unless I hit refresh
body: <p>Good morning, I finally managed to store the Facebook usernames in my database after Facebook login. The only problem is that the page where the user is redirected to after Facebook login needs to be reloaded (I get just an empty page the first time). Can you please refer to my previous question as I've already posted the all code <a href="https://stackoverflow.com/questions/10569922/facebook-php-sdk-store-user-data-into-mysql-database/10569945#comment13684457_10569945">there</a></p>
  
  <p>UPDATE: I noticed that the page needs to be refreshed only the first time (when the user info are not yet stored in the database, then it's loads the page quick and nicely. PLEASE HELP!;-)</p>
  
  <p>UPDATE2: is there a way to auto refresh the page (just once) after the new user has been added?
  many Thanks!</p>
  
  <p>UPDATE 3: I post the code.... it works only when i refresh the page.... any idea? </p>
  
  <pre><code>        &lt;?php
  
            mysql_connect('host', 'username', 'password');  
             mysql_select_db('table');  
  
  
  
  require 'library/facebook.php';
  
      // Create our Application instance 
     $facebook = new Facebook(array(
      'appId'  =&gt; 'MYID',
     'secret' =&gt; 'MYSECRET',
    'cookie' =&gt; true));
  
  
  // Get User ID
   $user = $facebook-&gt;getUser();
  
  
  
     if ($user) {
       try {
     // Proceed knowing you have a logged in user who's authenticated.
     $user_profile = $facebook-&gt;api('/me');
  
  
  
     } catch (FacebookApiException $e) {
     error_log($e);
     $user = null;
     }
       }else{
     header('location: index.php');
  
      }
        $query = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook' AND       oauth_uid = ". $user_profile['id']);  
        $result = mysql_fetch_array($query);  
  
      if(empty($result)){ 
        $query = mysql_query("INSERT INTO users (oauth_provider, oauth_uid, username)         VALUES ('facebook', {$user_profile['id']}, '{$user_profile['name']}')");  
         $query = msyql_query("SELECT * FROM users WHERE id = " . mysql_insert_id());  
        $result = mysql_fetch_array($query);  
  
         }  
  
  
  
      if ($user) {
       $paramsout = array('next'=&gt;'http://www.mywebsite/test/logout.php');
       $logoutUrl = $facebook-&gt;getLogoutUrl($paramsout);
       }
  
  
       ?&gt;
  </code></pre>
  
  <p>UPDATE 4*****: I found a solution. You can look on my answer below. Thanks to everybody.</p>