Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(!isset($_SESSION['user']))
- {
- //Application Configurations
- $app_id = "3xxxxxxx492";
- $app_secret = "0edd9byyyyyyyyyy62bb7";
- $site_url = "zzzzz.com";
- try{
- include_once "src/facebook.php";
- }catch(Exception $e){
- error_log($e);
- }
- // Create our application instance
- $facebook = new Facebook(array(
- 'appId' => $app_id,
- 'secret' => $app_secret,
- ));
- // Get User ID
- $fbid = $facebook->getUser();
- // We may or may not have this data based
- // on whether the user is logged in.
- // If we have a $fbid id here, it means we know
- // the user is logged into
- // Facebook, but we don’t know if the access token is valid. An access
- // token is invalid if the user logged out of Facebook.
- //print_r($fbid);
- if($fbid){
- // Get logout URL
- $logoutUrl = $facebook->getLogoutUrl();
- }else{
- // Get login URL
- $loginUrl = $facebook->getLoginUrl(array(
- 'scope' => 'read_stream, email, user_about_me',
- 'redirect_uri' => $site_url,
- ));
- }
- if($fbid){
- try{
- // Proceed knowing you have a logged in user who's authenticated.
- $fbid_profile = $facebook->api('/me');
- //Connecting to the database. You would need to make the required changes in the common.php file
- //In the common.php file you would need to add your Hostname, username, password and database name!
- mysqlc();
- $fullname = GetSQLValueString($fbid_profile['name'], "text");
- $email = GetSQLValueString($fbid_profile['email'], "text");
- $gender = GetSQLValueString($fbid_profile['gender'], "text");
- $bio = GetSQLValueString($fbid_profile['bio'], "text");
- $query = sprintf("SELECT * FROM newmember WHERE email = %s",$email);
- $res = mysql_query($query) or die('Query failed: ' . mysql_error() . "<br />\n$sql");
- if(mysql_num_rows($res) == 0)
- {
- $iquery = sprintf("INSERT INTO newmember values('',%s,%s,%s,%s,'yes')",$fullname,$email,$gender,$bio);
- $ires = mysql_query($iquery) or die('Query failed: ' . mysql_error() . "<br />\n$sql");
- $_SESSION['user'] = $fbid_profile['email'];
- $_SESSION['id'] = $fbid_profile['id'];
- }
- else
- {
- $row = mysql_fetch_array($res);
- $_SESSION['user'] = $row['email'];
- $_SESSION['id'] = $fbid_profile['id'];
- }
- }catch(FacebookApiException $e){
- error_log($e);
- $fbid = NULL;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement