FB redirection not working with custom image
<p>I am trying to allow user to login to my website using FB and then get redirected back to my website.  I am unsure why it is not working.  When I click on the image, it goes to FB website and then display "An error occurred. Please try again later."  Here is the code I am using and not sure if there is better code I should use.  I do not want to use the fb login button.  All I want teh user to do is click on my custom FB image and login and then redirect back to my website <a href="http://www.XXXXX.com/wp" rel="nofollow">http://www.XXXXX.com/wp</a>.</p>

<p>FB Button 
</p>

<p>Facebook.php
    

<pre><code>$app_id = XXXX;
$app_secret = "XXXX";
$my_url = "http://www.XXX.com/wp";


if(!isset( $_REQUEST["code"] ) ) {
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
    . $app_id . "&amp;redirect_uri=" . urlencode($my_url);

    echo("&lt;script&gt; top.location.href='" . $dialog_url . "'&lt;/script&gt;");
} else {
    $code = $_REQUEST["code"];
}

$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $app_id . "&amp;redirect_uri=" . urlencode($my_url) . "&amp;client_secret="
    . $app_secret . "&amp;code=" . $code;

$access_token = file_get_contents($token_url);

$graph_url = "https://graph.facebook.com/me?" . $access_token;

$user = json_decode(file_get_contents($graph_url));

echo("Hello " . $user-&gt;name);
?&gt;
</code></pre>
