Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; WP_MatchesMapRegex has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/class-wp.php on line 632

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Translation_Entry has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/entry.php on line 14

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_Reader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 12

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_FileReader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 120

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_StringReader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 175

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_CachedFileReader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 221

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_CachedIntFileReader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 236

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; WP_Widget_Factory has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/widgets.php on line 544

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzAdSense has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/easy-adsense-lite.php on line 38

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzAdsWidget has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/easy-adsense-lite.php on line 941

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzAdsSearch has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/easy-adsense-lite.php on line 1003

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzAdsLU has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/easy-adsense-lite.php on line 1078

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzBaseOption has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 22

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzCheckBox has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 174

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzRadioBox has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 199

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzSelect has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 250

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzMessage has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 294

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzHelpTag has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 313

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzHelpPopUp has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 328

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzTextArea has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 346

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzText has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 366

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzSubmit has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 385

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzColorPicker has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 409

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzOneTab has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 432

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzMiniTab has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 476
Login Google+ Using PHP - PHP Cơ Bản

Login Google+ Using PHP

Hiện nay, trên các website các bạn đều có thể thấy chức năng đăng nhập bằng tài khoản Google+. Điều này nghĩ là khó nhưng thực chất rất đơn giản, khi chúng ta sử dụng sự hỗ trợ từ OAuth2.

Trong bài viết này, mình sẽ chia sẻ với các bạn cách đăng nhập bằng tài khoản Google+ với cách sử dụng Google PHP API library và MySQL.

Đầu tiên, các bạn hãy truy cập vào link bên dưới để tải project trong đó. Trong đó mình đã bao gồm cả Google PHP API library.

https://github.com/cuongnv570/google_login_api/blob/master/google_login_api.rar

(Chọn View Raw để tải về)

Bước 2: Các bạn tạo một CSDL và tạo bảng google_users, các bạn có thể sử dụng PhpMyAdmin

Bước 3:

Các bạn cần phải có Client ID,Secret Key và Developer Key từ Google.Sau đây mình xin hướng dẫn chi tiết các bạn các bước thực hiện vấn đề này.

  1. Các bạn truy cập vào địa chỉ: https://console.developers.google.com
  2. Create a new project
  3. Ở thanh menu bên trái, các bạn click vào dòng APIs & auth.
  4. Ở thanh menu bên trái trong list APIs & auth, các bạn chọn vào APIs, chọn Google+ API, sau đó chọn ở chế độ Enable.
  5. Ở thanh menu bên trái trong list APIs & auth, các bạn chọn
  6. Tạo một API Key bằng cách chọn Create New Client ID, sau đó điền các thông tin đầy đủ theo yêu cầu, các bạn sẽ tìm thấy Client ID,Secret Key.
  • Chú ý:phần Redirect URIs các bạn nên điền link trực tiếp đến file index.php.
  1. Cuối cùng, các bạn chọn Create New Key, chọn Server Key, sau đó ấn Create, sẽ hiện ra thông tin của Server Key, trong đó API Key chính là Developer Key.

Bước 4: Bây giờ các bạn cần điền các thông tin vừa tìm kiếm ở trên vào các phần mình đánh dấu xxxxxxxxxxxxxxx trong file index.php.

 

Chú ý: $google_redirect_url các bạn nên link trực tiếp đến file index.php và để an toàn k bị mắc lỗi các bạn cũng nên đặt trong Redirect URIs phần cài client ID như vậy.Như của mình là http://localhost/google-login-api/index.php

Như vậy, mình đã giới thiệu với các bạn cách mình sử dụng để Login with Google+. Các bạn có thể tham khảo source code ở link download trên để hiểu thêm. Chúc các bạn thành công!!!!!

Đây là ảnh Demo project mình đã làm được!!!

l1

l2

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">