Page 1 sur 1

Problème de connexion Facebook

Posté : 15 févr. 2013, 16:54
par Dimitri54g
Bonjour à tous, j'ai un petit problème pour se connecter sur mon site grâce à Facebook
Quand je suis redirigé pour la connexion Facebook, ça ne fait que m'inscrire de nouveau à chaque fois car la fonction mysqli_num_rows est toujours vide.

Voici mon code

<?php

require_once "global.php";
require_once INCLUDES . 'facebook.php';

if (LOGGED_IN)
{
	header('Location: ' . WWW . DS . 'me');
	exit;
}

$facebook = new Facebook(array(
  'appId'  => $core->config['FACEBOOK']['APP_ID'],
  'secret' => $core->config['FACEBOOK']['APP_SECRET'],
));

$loginUrl = $facebook->getLoginUrl();
$user = $facebook->getUser();

if ($user) 
{
	try 
	{
		$profil = $facebook->api('me');
	} 
	
	catch (Exception $e) 
	{ 
		header('Location: ' . WWW);
		exit;
	}
}

else
{
	header('Location: ' . WWW);
	exit;
}

if ($users->FacebookIdExists($profil['id']))
{
	$user_id = $users->GetFacebookUserId($profil['id']);

	$_SESSION['username'] = $users->GetUserVar('username', $user_id);
	$_SESSION['password'] = $users->GetUserVar('password', $user_id);

	header('Location: ' . WWW . DS . 'me');
	exit;
} 

else 
{
	$email = utf8_decode($profil['email']);
	$username = utf8_decode($profil['first_name'] . $profil['last_name']);
	$username = filter(substr($username, 0, 16) . substr(str_shuffle('0123456789'), 0, 2));
	$password = $core->Hash($email . $username . time());

	$gender = ($profil['gender'] == "male") ? "M" : "F";
	$look = ($profil['gender'] == "male") ? "hd-180-1.ch-210-66.lg-270-82.sh-290-91.hr-100-" : "hd-180-1.ch-210-66.lg-270-82.sh-290-91.hr-100-";

	$users->Add($username, $password, $profil['name'], $email, 1, $look, $gender, $profil['id']);
	
	$_SESSION['username'] = $username;
	$_SESSION['password'] = $password;
	
	header('Location: ' . WWW . DS . 'me');
	exit;
}

?>
public function FacebookIdExists($id = 0)
	{
		return mysqli_num_rows(dbquery("SELECT null FROM users WHERE facebook_id = '" . $id . "' LIMIT 1"));
	}
public function GetFacebookUserId($id = 0)
	{
		return @mysqli_get_result(dbquery("SELECT id FROM users WHERE facebook_id = '" . $id . "' ORDER BY id DESC LIMIT 1"), 0);
	}

function dbquery($query = '')
{
	global $db;
	
	return $db->DoQuery($query);
}

function mysqli_get_result($query, $row, $field = 0)
{
	global $db;
	
	return @$db->GetResult($query, $row, $field);
}

public function DoQuery($query)
	{
		if ($this->IsConnected())
		{
			$result = mysqli_query($this->link, $query) or $this->Error(mysqli_error($this->link));
			
			return $result;
		}
	}

	public function GetResult($query, $row, $field = 0)
	{
		mysqli_data_seek($query, $row);
	
		if (strlen(trim($field)) > 0)
		{
			return mysqli_fetch_object($query)->$field;
		}
		
		$result = mysqli_fetch_row($query);
		return $result[0];
	}
J'espère que vous voudrez bien m'aider.