I am making my application for login on Facebook, however it returns with GET in url ?code=etc...
Before it was working normally, I use Facebook's class . See:
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
));
$user = $facebook->getUser();
#$facebook->setAccessToken($_REQUEST['access_token']);
if($user){
try {
$user_profile = $facebook->api('/me', 'GET');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
To log in I'm using the following option:
# There's no active session, let's generate one
$login_url = $facebook->getLoginUrl(array(
'scope' => 'email, user_about_me, user_friends,
user_birthday, publish_actions, read_stream, user_website',
'redirect_uri' => 'http://www.rifao.com.br/facebook/'
));
header("Location: " . $login_url);
The problem is that at the time of returning it keeps updating without stopping, since it is returning by the URL and not via session , I would like to know how to return it again via session ?
@ EDITION @
Files I'm using:
Configuration file (config.php):
define('APP_ID', '42826xxxxxx0624');
define('APP_SECRET', 'fd14bxxxxx04a1fbc');
File where facebook redirects (Login.php):
<?php
include("functions.php");
include("config.class.php");
include("config.php");
include("modules/Facebook/facebook.php");
if(@$atual[0]=="facebook"){
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
'cookie' => TRUE, /* Optional */
'oath' => TRUE /* Optional */
));
$access_token = $facebook->getAccessToken();
$user = $facebook->getUser();
if($user){
try {
$user_profile = $facebook->api('/me', 'GET');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
if (!empty($user_profile)){
# User info ok? Let's print it (Here we will be adding the login and registering routines)
$name = $user_profile['name'];
$uid = $user_profile['id'];
$email = $user_profile['email'];
$gender = $user_profile['gender'];
$birthday = $user_profile['birthday'];
$link = $user_profile['link'];
$user = new User();
if(!$user->checkUserFacebook($uid, $username, $email)){
echo '
<!-- Modal -->
<form action="javascript:func()" name="facebookLogin" id="facebookLogin" method="post" enctype="application/x-www-form-urlencoded" >
<div id="myModal" class="modal hide fade" tabindex="-1" data-keyboard="false" data-backdrop="static" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<h3 id="myModalLabel">Login com Facebook</h3>
</div>
<div class="modal-body">
<p>
<div class="alertLogin"></div>
<p class="text-info" id="inputType-name">Nome: <br>
<input class="span6" id="name" type="text" value="'.$name.'" placeholder="Digite seu nome completo"
';
if($name){echo ' disabled ';}
echo '
></p>
<p class="text-info" id="inputType-cpf">CPF:<br>
<input class="span6" id="cpf" name="cpf" type="text" placeholder="Digite seu CPF"></p>
<p class="text-info" id="inputType-email">E-mail:<br>
<input class="span6" id="email" name="email" type="text" value="'.$email.'" placeholder="Digite seu e-mail"
';
if($email){echo ' disabled ';}
echo '
></p>
<p class="text-info" id="inputType-phone">Telefone para contato (Somente mostrado caso for ganhador de RIFAS):<br>
<input class="span6" id="phone" id="phone" type="text" placeholder="Digite seu Telefone"></p>
<input type="hidden" value="'.$uid.'" name="uid" id="uid">
<input type="hidden" value="'.$gender.'" name="gender" id="gender">
<input type="hidden" value="'.$birthday.'" name="birthday" id="birthday">
<input type="hidden" value="'.$link.'" name="link" id="link">
<p class="text-info"><input type="checkbox" value="aceitou"> Você aceita nossos termos de uso?</p>
</p>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-rifao" type="submit">Salvar e logar</button>
</div>
</div>
</form>
';
}else{
$_SESSION["type"] = "facebook";
$_SESSION["uid"] = $uid;
header("Location: index.php");
exit();
}
} else {
die("There was an error.");
}
} else {
$login_url = $facebook->getLoginUrl(array(
'scope'=>'email, user_about_me, user_friends, user_birthday, publish_actions, read_stream, user_website',
'redirect_uri' => 'http://www.rifao.com.br/facebook/'
));
header("Location: " . $login_url);
}
}