偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

PHP使用Google Plus Oauth登錄

開發(fā) 后端
我已經使用PHP通過Google+數(shù)據(jù)簡單實現(xiàn)了一個稱為用戶身份驗證的登錄系統(tǒng)。試試這幾乎就像twitter登錄系統(tǒng),我希望未來Google+會釋放更多選項。

前陣子Google+已經發(fā)布了OAuth的應用程序編程接口,現(xiàn)在他們只提供用戶活動和循環(huán)數(shù)據(jù)。我已經使用PHP通過Google+數(shù)據(jù)簡單實現(xiàn)了一個稱為用戶身份驗證的登錄系統(tǒng)。試試這幾乎就像twitter登錄系統(tǒng),我希望未來Google+會釋放更多選項。

使用Google Plus Oauth登錄 

使用Google Plus Oauth登錄

第一步

 

點擊這里添加或者注冊你的域名。

添加或者注冊你的域名 

添加或者注冊你的域名

第二步

通過HTML文件上傳或包括META標簽來驗證您的域名所有權。

通過HTML文件上傳或包括META標簽來驗證您的域名所有權。 

通過HTML文件上傳或包括META標簽來驗證您的域名所有權。

第三步

谷歌將會提供你OAuth用戶密鑰和秘密密鑰。

谷歌將會提供你OAuth用戶密鑰和秘密密鑰 

谷歌將會提供你OAuth用戶密鑰和秘密密鑰

第四步

在Oauth控制臺創(chuàng)建客戶端ID(Client ID)。

在Oauth控制臺創(chuàng)建客戶端ID(Client ID) 

在Oauth控制臺創(chuàng)建客戶端ID(Client ID)

在Oauth控制臺創(chuàng)建客戶端ID(Client ID) 

在Oauth控制臺創(chuàng)建客戶端ID(Client ID)

第五步

應用的Oauth Client ID和客戶端密鑰(client secret)。

應用的Oauth Client ID和客戶端密鑰(client secret) 

應用的Oauth Client ID和客戶端密鑰(client secret)

下面來看一下我們的程序文件。

#p#

Config.php

在這里,你必須配置OAuth應用密鑰和用戶密鑰。

  1. // OAuth2 Settings, you can get these keys at https://code.google.com/apis/console Step 6 keys  
  2. 'oauth2_client_id' => 'App Client ID',  
  3. 'oauth2_client_secret' => 'App Client Secret',  
  4. 'oauth2_redirect_uri' => 'http://yoursite.com/gplus/index.php',  
  5.  
  6. // OAuth1 Settings Step 3  keys.  
  7. 'oauth_consumer_key' => 'OAuth Consumer Key',  
  8. 'oauth_consumer_secret' => 'OAuth Consumer Secret'

gplus_login.php

google+的登錄系統(tǒng)。

  1. <?php  
  2. require_once 'src/apiClient.php';  
  3. require_once 'src/contrib/apiPlusService.php';  
  4. session_start ();  
  5. $client = new apiClient ();  
  6. $client->setApplicationName ( "9lessons Google+ Login Application" );  
  7. $client->setScopes ( array ('https://www.googleapis.com/auth/plus.me' ) );  
  8. $plus = new apiPlusService ( $client );  
  9. if (isset ( $_REQUEST ['logout'] )) {  
  10.     unset ( $_SESSION ['access_token'] );  
  11. }  
  12.  
  13. if (isset ( $_GET ['code'] )) {  
  14.     $client->authenticate ();  
  15.     $_SESSION ['access_token'] = $client->getAccessToken ();  
  16.     header ( 'Location: http://' . $_SERVER ['HTTP_HOST'] . $_SERVER ['PHP_SELF'] );  
  17. }  
  18.  
  19. if (isset ( $_SESSION ['access_token'] )) {  
  20.     $client->setAccessToken ( $_SESSION ['access_token'] );  
  21. }  
  22.  
  23. if ($client->getAccessToken ()) {  
  24.     $me = $plus->people->get ( 'me' );  
  25.     $_SESSION ['access_token'] = $client->getAccessToken ();  
  26. else 
  27.     $authUrl = $client->createAuthUrl ();  
  28.  
  29. if (isset ( $me )) {  
  30.     $_SESSION ['gplusdata'] = $me;  
  31.     header ( "location: home.php" );  
  32. }  
  33.  
  34. if (isset ( $authUrl ))  
  35.     print "<a class='login' href='$authUrl'>Google Plus Login </a>";  
  36. else 
  37.     print "<a class='logout' href='index.php?logout'>Logout</a>";  
  38. ?> 

home.php

這里包含了將google+的session信息插入user數(shù)據(jù)表的PHP代碼。

  1. <?php  
  2. session_start();  
  3. if (!isset($_SESSION['gplusdata'])) {  
  4.     // Redirection to home page  
  5.     header("location: index.php");  
  6. }else{  
  7.     $me=$_SESSION['gplusdata'];  
  8.     echo "<img src='{$me['image']['url']}'/>";  
  9.     echo "Name: {$me['displayName']}";  
  10.     echo "Gplus Id:  {$me['id']}";  
  11.     echo "Male: {$me['gender']}";  
  12.     echo "Relationship: {$me['relationshipStatus']}";  
  13.     echo "Location: {$me['placesLived'][0]['value']}";  
  14.     echo "Tagline: {$me['tagline']}";  
  15.     print "<a class='logout' href='index.php?logout'>Logout</a> ";  
  16. }  
  17. ?> 

下面附上使用Google Plus Oauth登錄的示例源碼:下載點這里

原文鏈接:http://www.phpfuns.com/php/login-with-google-plus-oauth.shtml

【編輯推薦】

責任編輯:張偉 來源: phpFuns
相關推薦

2012-10-12 10:30:37

PHPOauth

2012-06-13 10:49:23

PHP

2012-05-31 13:59:43

PHP

2011-01-20 10:12:06

ibmdwPHPGoogle

2013-05-16 11:11:41

Google

2012-11-07 10:01:52

組件技術OAuth授權登陸

2023-08-29 08:00:38

2012-04-19 10:52:52

2010-03-29 13:39:41

ibmdwPHP

2015-03-13 15:21:23

phpgoogleapi

2009-12-10 17:37:28

PHP Cookie登

2010-02-24 15:25:41

ibmdwGooglePHP

2009-04-16 09:59:16

Google App PHPJava

2009-06-29 13:28:18

PHP小組PHP技巧網站加速

2022-08-15 08:34:08

OauthCAS登錄

2010-04-21 09:53:24

2018-06-10 15:30:36

2024-09-11 08:37:39

2012-05-24 10:15:48

PHP

2025-04-29 09:07:21

點贊
收藏

51CTO技術棧公眾號