Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

detect_facebook.php

By: a guest on May 2nd, 2012  |  syntax: PHP  |  size: 4.78 KB  |  views: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. require 'facebook.php';
  4.  
  5. if (isset($_SESSION['fb_277467322296156_user_id'])) {
  6.  
  7.         $facebook = new Facebook( array('appId' => '**APPID', 'secret' => '**SECRETID***', ));
  8.         $user = $facebook -> getUser();
  9.  
  10.         if ($user) {
  11.                 try {
  12.                         // Proceed knowing you have a logged in user who's authenticated.
  13.                         $user_profile = $facebook -> api('/me');
  14.                 } catch (FacebookApiException $e) {
  15.                         error_log($e);
  16.                         $user = null;
  17.                 }
  18.         }
  19.         $femail = $user_profile['email'];
  20.         $fname = $user_profile['name'];
  21.         $fname = htmlentities(strip_tags($fname), ENT_COMPAT, "UTF-8");
  22.         $femail = htmlentities(strip_tags($femail), ENT_COMPAT, "UTF-8");
  23.         $fsex = $user_profile['gender'];
  24.         $fsex = htmlentities(strip_tags($fsex), ENT_COMPAT, "UTF-8");
  25.         if ($fsex == "male") {
  26.                 $ag = "1";
  27.         } else {
  28.                 $ag = "0";
  29.         }
  30.  
  31.         $ffirstname = $user_profile['first_name'];
  32.         $flastname = $user_profile['last_name'];
  33.  
  34.         $date = explode('/', $user_profile['birthday']);
  35.         $fbirthday = $date[2] . "/" . $date[0] . "/" . $date[1];
  36.  
  37.         $fcity = $user_profile['hometown']['name'];
  38.  
  39.         $query = "SELECT USERID FROM members WHERE email='" . mysql_real_escape_string($femail) . "' limit 1";
  40.         $executequery = $conn -> execute($query);
  41.         $FUID = intval($executequery -> fields['USERID']);
  42.         if ($FUID > 0) {
  43.                 $query = "SELECT USERID,email,username,verified,gender from members WHERE USERID='" . mysql_real_escape_string($FUID) . "' and status='1'";
  44.                 $result = $conn -> execute($query);
  45.                 if ($result -> recordcount() > 0) {
  46.                         $query = "update members set lastlogin='" . time() . "', lip='" . $_SERVER['REMOTE_ADDR'] . "' WHERE USERID='" . mysql_real_escape_string($FUID) . "'";
  47.                         $conn -> execute($query);
  48.  
  49.                         $_SESSION['USERID'] = $result -> fields['USERID'];
  50.                         $_SESSION['EMAIL'] = $result -> fields['email'];
  51.                         $_SESSION['USERNAME'] = $result -> fields['username'];
  52.                         $_SESSION['VERIFIED'] = $result -> fields['verified'];
  53.                         $_SESSION['GENDER'] = $result -> fields['gender'];
  54.                         $_SESSION['FB'] = "1";
  55.  
  56.                 }
  57.         } else {
  58.                 $md5pass = md5(generateCode(5) . time());
  59.  
  60.                 if ($fname != "" && $femail != "") {
  61.  
  62.                         $query = "INSERT INTO members SET email='" . mysql_real_escape_string($femail) . "',birthday='" . mysql_real_escape_string($fbirthday) . "',city='" . mysql_real_escape_string($fcity) . "',username='" . mysql_real_escape_string($fname) . "',firstname='" . mysql_real_escape_string($ffirstname) . "',lastname='" . mysql_real_escape_string($flastname) . "', password='" . mysql_real_escape_string($md5pass) . "', addtime='" . time() . "', lastlogin='" . time() . "', ip='" . $_SERVER['REMOTE_ADDR'] . "', lip='" . $_SERVER['REMOTE_ADDR'] . "', verified='1', gender='" . $ag . "'";
  63.                         $result = $conn -> execute($query);
  64.                         $userid = mysql_insert_id();
  65.                         if ($userid != "" && is_numeric($userid) && $userid > 0) {
  66.  
  67.                                 $query = "SELECT USERID,email,username,verified,gender from members WHERE USERID='" . mysql_real_escape_string($userid) . "'";
  68.                                 $result = $conn -> execute($query);
  69.  
  70.                                 $_SESSION['USERID'] = $result -> fields['USERID'];
  71.                                 $_SESSION['EMAIL'] = $result -> fields['email'];
  72.                                 $_SESSION['USERNAME'] = $result -> fields['username'];
  73.                                 $_SESSION['VERIFIED'] = $result -> fields['verified'];
  74.                                 $_SESSION['SGENDER'] = $result -> fields['gender'];
  75.                                 $_SESSION['FB'] = "1";
  76.  
  77.                                 $url = "http://graph.facebook.com/$user/picture?type=large";
  78.                                 $sourceFilePath = CurlHelper::downloadFile($url, array('followLocation' => true, 'maxRedirs' => 5, ));
  79.  
  80.                                 $theimageinfo = getimagesize($sourceFilePath);
  81.                                 $thepp = $_SESSION['USERID'];
  82.  
  83.                                 if ($theimageinfo[2] == 1) {
  84.                                         $thepp .= ".gif";
  85.                                 } elseif ($theimageinfo[2] == 2) {
  86.                                         $thepp .= ".jpg";
  87.                                 } elseif ($theimageinfo[2] == 3) {
  88.                                         $thepp .= ".png";
  89.                                 }
  90.  
  91.                                 $myvideoimgnew = $config['membersprofilepicdir'] . "/" . $thepp;
  92.  
  93.                                 $thumb = PhpThumbFactory::create($sourceFilePath);
  94.  
  95.                                 //on save tel quel
  96.                                 $thumb -> save($myvideoimgnew);
  97.                                 //on redimensionne la photo
  98.                                 $thumb -> resize(100, 100);
  99.                                 // save dans le bon rep
  100.                                 $tothumbdir = $config['membersprofilepicdir'] . "/thumbs/" . $thepp;
  101.                                 $thumb -> save($tothumbdir);
  102.  
  103.                                 if (file_exists($config['membersprofilepicdir'] . "/" . $thepp)) {
  104.                                         $query = "UPDATE members SET profilepicture='$thepp' WHERE USERID='" . mysql_real_escape_string($_SESSION['USERID']) . "'";
  105.                                         $conn -> execute($query);
  106.                                 } else {
  107.                                         $error = "$lang[135]";
  108.                                 }
  109.  
  110.                         }
  111.                 }
  112.         }
  113. } else {
  114.         $params = array(scope => 'email, user_birthday');
  115.  
  116.         $loginUrl = $facebook -> getLoginUrl($params);
  117.         $loginLien = "<a href='$loginUrl'><img id='fb_login_image' src='http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_short.gif' alt='Login Facebook'/></a>";
  118.  
  119.         STemplate::assign('loginFB', $loginLien);
  120.  
  121. }
  122. ?>
  123.  
  124. <h3>PHP Session</h3>
  125. <pre><?php print_r($_SESSION);?></pre>