Allora nella pagina index.php ho inserito il login cosi richiamato:
Codice PHP:
[url="login-facebook.php"][img]http://www.mondodc.it/dr.house/images/login-face.png[/img][/url]
Invio il richiamo alla pagina login-facebook.php
Codice PHP:
<?php ob_start ();
require 'facebook/facebook.php';
require 'config/fbconfig.php';
require 'config/functions.php';
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
'cookie' => true
));
$session = $facebook->getSession();
if (!empty($session)) {
# Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
try {
$uid = $facebook->getUser();
$user = $facebook->api('/me');
} catch (Exception $e) {
}
if (!empty($user)) {
# User info ok? Let's print it (Here we will be adding the login and registering routines)
echo '<pre>';
print_r($user);
echo '</pre>
';
$username = $user['name'];
$user = new User();
$userdata = $user->checkUser($uid, 'facebook', $username);
if(!empty($userdata)){
session_start();
$_SESSION['id'] = $userdata['id'];
$_SESSION['oauth_id'] = $uid;
$_SESSION['username'] = $userdata['username'];
$_SESSION['oauth_provider'] = $userdata['oauth_provider'];
header("Location: benvenuto1.php");
}
} else {
# For testing purposes, if there was an error, let's kill the script
die("There was an error.");
}
} else {
# There's no active session, let's generate one
$login_url = $facebook->getLoginUrl();
header("Location: " . $login_url);
}
?>
come potete notare infondo header("Location: benvenuto1.php"); ho inserito il richiamo alla pagina che si deve collegare in questo passaggio che quando premo su login non mi fa il login ma mi rimanda sul sito di facebook.com
ora vi posto i tre richiami al login:
require 'facebook/facebook.php'; che non vi pubblico che penso sia il codice universale delle api di facebook.
require 'config/fbconfig.php';
Codice PHP:
<?php
define('APP_ID', 'id app');
define('APP_SECRET', 'app secret');
?>
require 'config/functions.php';
Codice PHP:
<?php
require 'dbconfig.php';
class User {
function checkUser($uid, $oauth_provider, $username)
{
$query = mysql_query("SELECT * FROM `users` WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'") or die(mysql_error());
$result = mysql_fetch_array($query);
if (!empty($result)) {
# User is already present
} else {
#user not present. Insert a new Record
$query = mysql_query("INSERT INTO `users` (oauth_provider, oauth_uid, username) VALUES ('$oauth_provider', $uid, '$username')") or die(mysql_error());
$query = mysql_query("SELECT * FROM `users` WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
$result = mysql_fetch_array($query);
return $result;
}
return $result;
}
}
?>
infine ho il richiamo classico al DB:
Codice PHP:
<?php
define('DB_SERVER', 'server');
define('DB_USERNAME', 'user');
define('DB_PASSWORD', 'pass');
define('DB_DATABASE', 'db');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
?>
a me i codici sembrano in ordine. ... spero in risposte.... grazie a tutti