Today, We want to share with you OAuth Login with Facebook and Twitter using PHP.
In this post we will show you Login with Facebook using PHP, hear for we will give you demo and example for implement.In this post, we will learn about OAuth Login for Facebook Twitter and Google Plus Using PHP with an example.

Login with Facebook and Twitter using PHP

There are the Following The simple About OAuth Login with Facebook and Twitter using PHP Full Information With Example and source code.

Steps 1 : Download HybridAuth PHP library

Steps 1: first of all We have simple used redymate library such as a HybridAuth Library with this step by step fully working example, Therefor you simple here need all the source code download HybridAuth PHP library from here all source code on Github.

Steps 2 : Create Facebook and Twitter developer Account

Now, Steps 2: You some legaly should to retrive main social Developer main API(OAuth – authentication) Key as well as get Secret from your Developer accounts created and get all config data in Facebook and Twitter for Login with Facebook and Twitter using PHP.

READ :  AngularJs ng click and ng touch mobile device

Steps 3 :config for Twitter with Facebook

Steps3: And then you should to make simple changes config.php as well as put here below source code to this file.

$config =array(
"base_url" => "",
"sources" => array (
"Facebook" => array (
"enabled" => true,
"keys" => array ( "id" => "Inf454nityPak574infops5SSkd", "secret" => "Inf454nityPak574infops5SSkd" ),
"Twitter" => array (
"enabled" => true,
"keys" => array ( "key" => "Inf454nityPak574infops5SSkd", "secret" => "Inf454nityPak574infops5SSkd" )
"debug_mode" => false,
"debug_file" => "",

Auto Post Tweets on Twitter via API Using PHP

Steps 4 : Facebook and Twitter Login(index.php)

Steps 4: and then make a simple main root file name index.php as well as put the below source code.

<div align="center">
<a href="login.php?source=Facebook"><img src=''></img></a> <br><br>
<a href="login.php?source=Twitter"><img src=''></img></a> <br><br>

Steps 5 : Login with Facebook and Twitter

Steps 5: Now, You will should to make new login.php as well put The below source code.

READ :  vuejs Nested v-repeat Iterating Over Items directive

//PHP start session

//Include path of hybridauth Library

//check proviedes
if(isset($_GET['source'])) {
$source = $_GET['source'];
try {
$hybridauth = new Hybrid_Auth( $config );
$authProvider = $hybridauth->authenticate($source);
$scoial_profile = $authProvider->getUserProfile();
if($scoial_profile && isset($scoial_profile->identifier)) {
echo "<b>Your Name</b> :".$scoial_profile->displayName."<br>";
echo "<b>Img URL</b> :".$scoial_profile->profileURL."<br>";
echo "<b>Your Image</b> :".$scoial_profile->photoURL."<br> ";
echo "<img src='".$scoial_profile->photoURL."'/><br>";
echo "<b>Your Email Address</b> :".$scoial_profile->email."<br>";
echo "<br> <a href='logout.php'>Logout</a>";
catch( Exception $e ) {
switch( $e->getCode() ) {
case 0 : echo "Unspecified some stuck error."; break;
case 1 : echo "Hybridauth libs configuration error."; break;
case 2 : echo "Provider not good configured."; break;
case 3 : echo "Unknown or disabled source."; break;
case 4 : echo "Missing source any devloper application credentials."; break;
case 5 : echo "Authentication failed. "
. "The clients has canceled the web authentication or the source refused the main connection.";
case 6 : echo "clients your request failed. Most likely the clients is not connected "
. "to the source and he should to authenticate again.";
case 7 : echo "clients not connected to the source.";
case 8 : echo "Provider does not proviedes this feature."; break;
echo "<br /><br /><b>Original error message:</b> " . $e->getMessage();
echo "<hr /><h3>Trace</h3> <pre>" . $e->getTraceAsString() . "</pre>";

Step 6 : Logout with Facebook and Twitter

Steps 6:Last step to make file name logout.php with the below some source code to handle your all the pages not access with logout functionality.

READ :  Timepicker Angularjs Example - Timepicker Example angular-time-picker

//PHP session start
header("Location: index.php");

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Login with Facebook and Twitter.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.