Hace tiempo que no consigo que el Facebook login me funcione completamente... lo tuve funcionando y se registraron usuarios pero algo hice que dejó de funcionar...
Entonces, lo he estado toqueteando otra vez y ahora, almenos, los que se registraron pueden iniciar sesión, pero los que nó; reciben este error...
Código:
Mi dominio es keepyourlinks.com Fatal error: Uncaught exception 'FacebookRestClientException' with message'Unauthorized source IP address' in /home/piscolab/public_html/keepyourlinks.com/fb/php/facebookapi_php5_restlib.php:3065 Stack trace: #0 /home/piscolab/public_html/keepyourlinks.com/fb/php/facebookapi_php5_restlib.php(1717): FacebookRestClient->call_method('facebook.users....', Array) #1 /home/piscolab/public_html/keepyourlinks.com/facebook.php(103): FacebookRestClient->users_getInfo('1006681652', Array) #2 {main} thrown in /home/piscolab/public_html/keepyourlinks.com/fb/php/facebookapi_php5_restlib.php on line 3065
Este error lo recibe cuando ya ha iniciado sesión en facebook y mi sistema lo ha reconocido, le pido un nombre de usuario para mi web y al confirmar recibe este error... :S
mi codigo
Código PHP:
<?
$FB_API_KEY = "llllllllllll";
$FB_SECRET = "+++++";
?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<script src="http://static.new.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<meta name="keywords" content="Facebook connect keepyourlinks"/>
<meta name="description" content="Login With Facebook"/>
<title> Login with Facebook in keepyourlinks.com - Facebook will ask your for permision </title>
<link href="css/mis_estilos.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="js/ajax.js"></script>
</head>
<body>
<?
?>
<div class="caja" style="float:center; margin-top:150px; padding:50px;">
<?
session_start();
//
// this file includes FB_API_KEY and FB_SECRET constants and the ConnectDB function
// to connect to your mysql database.
include('./php/configuracion.php');
//
// the php facebook api downloaded at step 3
include('./fb/php/facebook.php');
//
// start facebook api with the codes defined in step 1.
$fb=new Facebook($FB_API_KEY,$FB_SECRET);
$fb_user=$fb->get_loggedin_user();
if($fb_user) {
//
// if we already have a user ID cookie than we link
// in the database this user with his facebook account
// using the fb_userid field.
// this code assumes that when a user login in your
// community you set up a value in a cookie called "myid".
// this cookie is the one that you use when you want
// to remember the user:
//
// with the user id from facebook retrived with the API,
// search for a user already registered with this process:
$rs = mysql_query("SELECT * FROM usuarios WHERE fid='$fb_user'");
if (mysql_num_rows($rs))
$u = mysql_fetch_array($rs);
else
$u="";
if (is_array($u)) {
//
// this is a user connected with facebook
// and already existing on your community.
// So, log in automatically with user and password of
// your community. These lens print a form and submit it
// to your real login page:
// (change the address in the action to match your normal login page)
$_SESSION['alias'] = $u['alias'];
$_SESSION['logueado'] = true;
$_SESSION['id'] = $u['id'];
header("Location: http://keepyourlinks.com/");
} else {
if($_POST['username']){
//
// this is a user logged in on facebook
// but it doesn't exists on your community,
// it's new!
// So let's create automatically the user and log in!
//
// get some user details from facebook api
$user_details = $fb->api_client->users_getInfo($fb_user, array('last_name','first_name'));
//
// write out some message to welcome the new user:
$alias = $_POST['username']; //
// generate random password for new user:
$pass = "fb";
//
// empty email:
$email = "[email protected]";
//create the user on your table
$sql = "INSERT INTO usuarios (alias, email, fecha, comparte, fid) VALUES ('$alias','$email',NOW(), '$comparte', '$fb_user')";
$insert = mysql_query($sql);
//
// new user created, log him in:
$notiduser = mysql_query("SELECT * FROM usuarios WHERE alias='$alias'");
while($notid = mysql_fetch_array($notiduser)){
$id= $notid['id'];
}
$comparte = true;
echo "<p><img src='../images/confirm.png' alt='link' width='25' height='25' /> User Registred Succesfully </p>";
$query1 = "INSERT INTO categorias (idpadre,iduser, nombre, public) VALUES('0','$id','Uncategorized','1')";
mysql_query($query1) or die(mysql_error());
echo "<img src='../images/confirm.png' alt='link' width='20' height='20' /> Resultado: Perfection";
echo '<p>ya registrado, por tanto login</p>';
$_SESSION['alias'] = $alias;
$_SESSION['logueado'] = true;
$_SESSION['id'] = $id;
$_SESSION['comparte'] = $u['comparte'];
header("Location: http://keepyourlinks.com/");
}else{
echo '<div id="stylized" class="myform">
<form id="form" name="login" method="post" action="facebook.php">
<label>Name
<span class="small">Enter the name you want for your profile</span>
</label>
<input type="text" name="username" id="username">
<button type="submit" name="enviar" value="Login">Create Account</button>
<div class="spacer"></div>
</form>
</div>';
}
}
} else{
//
// the user probably isn't logged in on facebook, put out
// the facebook button and clicking on it it will open a pop uo
// that requires the login on facebook to proceed.
// the "onlogin" command refresh the page.
echo '<div><h2 style="text-align:center;">Click to log on keepyourlinks.com with your facebook account.</h2 style="margin:40px;"><center><fb:login-button size="medium" onlogin="document.location.href=document.location.href;"></fb:login-button><center>';
}
?>
<script type="text/javascript">FB.init("<?=$FB_API_KEY;?>","xd_receiver.htm");</script>
</body>
</html>