im attempting to import "sign in with facebook" chance to my website, im using, but nonetheless cannot have great results. I register my website and also have application id and application secret. I've the next code during my login form:

 <a href="facebook.php"><img src="images/facebook-login-button.png" /></a>

facebook.php file:


$application_id = 1000000000000

$application_secret = "asdasdasdasd"

$my_url = "http://xxxx.xx/"

$code = $_REQUEST["code"]

if(empty($code)) world wide"

        . $application_id . "&redirect_uri=" . urlencode($my_url)

    echo("<script> top.location.href='" . $dialog_url . "'</script>")

$token_url = ""

    . $application_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="

    . $application_secret . "&code=" . $code

$access_token = file_get_contents($token_url)

$graph_url = "" . $access_token

$user = json_decode(file_get_contents($graph_url))

echo("Hello " . $user->name)


It returns message "undefined index code" and that i have no clue where and things to change.

Please, help!

The mistake you are getting is suggesting the "code" parameter you are searching for within the request:

$code = $_REQUEST["code"]

isn't being posted.. E.g. you can either have to publish "code" towards the page or pass it via GET using facebook.php?code=something

To prevent running into errors once the parameter "code" isn't sent, your code could seem like:

if(!isset( $_REQUEST["code"] ) ) world wide"

        . $application_id . "&redirect_uri=" . urlencode($my_url)

    echo("<script> top.location.href='" . $dialog_url . "'</script>")


Hope that can help..