require_once('facebook/src/facebook.php'); $facebook = new Facebook(array( 'appId' => '1540338029543969', 'secret' => '6477812e3708dc24485f57f6ddcdf675', /*'fileupload' => false, 'allowSignedRequest' => false,*/ )); // See if there is a user from a cookie ; $user = $facebook->getUser(); if ($user) { try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); if ($user) { $fbfname=$user_profile[first_name]; $fblname=$user_profile[last_name]; $fbsex=$user_profile[gender]; $fbname=$user_profile[name]; $fbid=$user_profile[id]; $fbemail=$user_profile[email]; date_default_timezone_set('Asia/Calcutta'); $fbdate = date('m/d/Y h:i:s a', time()); $sel=mysql_query("select * from fbdata where fb_id='$fbid'")or die("Select".mysql_error()); echo $ct=mysql_num_rows($sel); if($ct==1){ $row=mysql_fetch_array($sel); $urid=$row['fb_id']; $_SESSION['usrid']=$urid; $_SESSION['type']='facebook'; $_SESSION['logtime']=$fbdate; }else{ mysql_query("insert into fbdata(fname,lname,email,reg_date,fb_id) values ('$fbfname','$fblname','$fbemail','$fbdate','$fbid')")or die("INSERT".mysql_error()); $_SESSION['usrid']=$userfb_id; $_SESSION['type']='facebook'; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class OS_BR{ private $agent = ""; private $info = array(); function __construct(){ $this->agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : NULL; $this->getBrowser(); $this->getOS(); } function getBrowser(){ $browser = array("Navigator" => "/Navigator(.*)/i", "Firefox" => "/Firefox(.*)/i", "Internet Explorer" => "/MSIE(.*)/i", "Google Chrome" => "/chrome(.*)/i", "MAXTHON" => "/MAXTHON(.*)/i", "Opera" => "/Opera(.*)/i", ); foreach($browser as $key => $value){ if(preg_match($value, $this->agent)){ $this->info = array_merge($this->info,array("Browser" => $key)); $this->info = array_merge($this->info,array( "Version" => $this->getVersion($key, $value, $this->agent))); break; }else{ $this->info = array_merge($this->info,array("Browser" => "UnKnown")); $this->info = array_merge($this->info,array("Version" => "UnKnown")); } } return $this->info['Browser']; } function getOS(){ $OS = array("Windows" => "/Windows/i", "Linux" => "/Linux/i", "Unix" => "/Unix/i", "Mac" => "/Mac/i" ); foreach($OS as $key => $value){ if(preg_match($value, $this->agent)){ $this->info = array_merge($this->info,array("Operating System" => $key)); break; } } return $this->info['Operating System']; } function getVersion($browser, $search, $string){ $browser = $this->info['Browser']; $version = ""; $browser = strtolower($browser); preg_match_all($search,$string,$match); switch($browser){ case "firefox": $version = str_replace("/","",$match[1][0]); break; case "internet explorer": $version = substr($match[1][0],0,4); break; case "opera": $version = str_replace("/","",substr($match[1][0],0,5)); break; case "navigator": $version = substr($match[1][0],1,7); break; case "maxthon": $version = str_replace(")","",$match[1][0]); break; case "google chrome": $version = substr($match[1][0],1,10); } return $version; } function showInfo($switch){ $switch = strtolower($switch); switch($switch){ case "browser": return $this->info['Browser']; break; case "os": return $this->info['Operating System']; break; case "version": return $this->info['Version']; break; case "all" : return array($this->info["Version"], $this->info['Operating System'], $this->info['Browser']); break; default: return "Unkonw"; break; } } } // using // create an new instant of OS_BR class $obj = new OS_BR(); // // if you want to show one by one information then try showInfo() function // get browser $logbrowser= $obj->showInfo('browser'); // get browser version $bversion= $obj->showInfo('version'); // get Operating system $osinfo= $obj->showInfo('os'); // get all information and it returns an array //echo "
".print_r($obj->showInfo("all"),true)."
"; ///////////////////////////////////////////////////////////////////// /*if ($rem == "s") //if the Remember me is checked, it will create a cookie. { setcookie("uname", $username, time()+7600,"/"); setcookie("pass", $password, time()+7600,"/");*/ //here we are setting a cookie named username, with the Username on the database that will last 48 hours and will be set on the understandesign.com domain. This is an optional parameter. mysql_query("INSERT INTO loginchart (`username`,`time`,`browser`,`browserv`,`os`,`logintype`) VALUES('$fbid','$fbdate','$logbrowser','$bversion','$osinfo','Facebook')"); $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if (false !== strpos($url,'login.php')) { header('location:../index.php'); } else { header('location:'.$url); } } } catch (FacebookApiException $e) { $login_url= $facebook -> getLoginUrl(); $user = null; } } else { $login_url= $facebook -> getLoginUrl(); }