fetch_object(); } /* * get the user data from database by email and password **/ function get_user_by_email_and_password( $email, $password ) { return mysqli_query_excute( "SELECT * FROM users WHERE email = '$email' AND password = '$password'" ); } /* * get the user data from database by provider name and provider user id **/ function get_user_by_provider_and_id( $provider_name, $provider_user_id ) { return mysqli_query_excute( "SELECT * FROM users WHERE hybridauth_provider_name = '$provider_name' AND hybridauth_provider_uid = '$provider_user_id'" ); } /* * get the user data from database by provider name and provider user id **/ function create_new_hybridauth_user( $email, $first_name, $last_name, $provider_name, $provider_user_id ) { // let generate a random password for the user $password = md5( str_shuffle( "0123456789abcdefghijklmnoABCDEFGHIJ" ) ); mysqli_query_excute( "INSERT INTO users ( email, password, first_name, last_name, hybridauth_provider_name, hybridauth_provider_uid, created_at ) VALUES ( '$email', '$password', '$first_name', '$last_name', $provider_name, $provider_user_id, NOW() )" ); } // if page requested by submitting login form if( isset( $_REQUEST["email"] ) && isset( $_REQUEST["password"] ) ) { $user_exist = get_user_by_email_and_password( $_REQUEST["email"], $_REQUEST["password"] ); // user exist? if( $user_exist ) { // set the user as connected and redirect him to a home page or something $_SESSION["user_connected"] = true; header("Location: http://www.example.com/user/home.php"); } // wrong email or password? else { // redirect him to an error page header("Location: http://www.example.com/login-error.php"); } } // else, if login page request by clicking a provider button elseif( isset( $_REQUEST["provider"] ) ) { // the selected provider $provider_name = $_REQUEST["provider"]; try { // change the following paths if necessary $config = dirname(__FILE__) . '/library/config.php'; require_once( "library/Hybrid/Auth.php" ); // initialize Hybrid_Auth with a given file $hybridauth = new Hybrid_Auth( $config ); // try to authenticate with the selected provider $adapter = $hybridauth->authenticate( $provider_name ); // then grab the user profile $user_profile = $adapter->getUserProfile(); } // something went wrong? catch( Exception $e ) { header("Location: http://www.example.com/login-error.php"); } // check if the current user already have authenticated using this provider before $user_exist = get_user_by_provider_and_id( $provider_name, $user_profile->identifier ); // if the used didn't authenticate using the selected provider before // we create a new entry on database.users for him if( ! $user_exist ) { create_new_hybridauth_user( $user_profile->email, $user_profile->firstName, $user_profile->lastName, $provider_name, $user_profile->identifier ); } // set the user as connected and redirect him $_SESSION["user_connected"] = true; header("Location: http://www.example.com/user/home.php"); } ?> Simple Social Login Integration - HybridAuth
Sign-in form Email :
Password:
Or use another service Signin with Facebook - Signin with Twitter - Signin with Linkedin