{"id":3407,"date":"2018-08-07T20:43:33","date_gmt":"2018-08-07T20:43:33","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=3407"},"modified":"2022-07-28T06:01:38","modified_gmt":"2022-07-28T06:01:38","slug":"login-with-github-oauth-api-using-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/","title":{"rendered":"Login with GitHub OAuth API using PHP"},"content":{"rendered":"<p>GitHub provides a web-based hosting service for version control. It plays an important role in software and web development. Presently GitHub has over 28 million users from around the world. If you want to allow users to log in with their social account, GitHub can be the best option besides the other social media OAuth Login (<a href=\"https:\/\/www.codexworld.com\/login-with-facebook-using-php\/\">Facebook OAuth API<\/a>, <a href=\"https:\/\/www.codexworld.com\/login-with-google-api-using-php\/\">Google OAuth API<\/a>, <a href=\"https:\/\/www.codexworld.com\/login-with-twitter-using-php\/\">Twitter OAuth API<\/a>, etc.). <b>GitHub OAuth Login<\/b> is a quick and powerful way to integrate user login system into the web application.<\/p>\n<p>GitHub authentication API allows the users to sign in to the website using their GitHub account without registration on your website. <b>Login with GitHub<\/b> account can be easily implemented using GitHub OAuth API. In this tutorial, we will show you how to integrate the user login and registration system with GitHub using PHP and store the user&#8217;s profile data in the MySQL database.<\/p>\n<p>Before getting started, take a look at the file structure to implement <b>GitHub Login with PHP<\/b>.<\/p>\n<pre class=\"file-struc\">github_login_with_php<span style=\"color:#794938\">\/<\/span>\r\n\u251c\u2500\u2500 config.php\r\n\u251c\u2500\u2500 index.php\r\n\u251c\u2500\u2500 logout.php\r\n\u251c\u2500\u2500 User.class.php\r\n\u251c\u2500\u2500 src<span style=\"color:#794938\">\/<\/span>\r\n\u2502   \u2514\u2500\u2500Github_OAuth_Client.php\r\n\u251c\u2500\u2500 css<span style=\"color:#794938\">\/<\/span>\r\n\u2502   \u2514\u2500\u2500 style.css\r\n\u2514\u2500\u2500 images<span style=\"color:#794938\">\/<\/span>\r\n    \u2514\u2500\u2500 github-login.png\r\n<\/pre>\n<h2>Create GitHub OAuth Application<\/h2>\n<p>You need to create and register OAuth App to access GitHub API. Also, the Client ID and Client Secret need to be specified at the time of the GitHub API call. Follow the below steps to create and configure the GitHub OAuth application.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Log in to your <a href=\"https:\/\/github.com\/login\" target=\"_blank\" rel=\"noopener\">GitHub account<\/a>. In the upper-right corner, click your profile picture and then click <b>Settings<\/b>.\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-account-settings-codexworld.png\" alt=\"github-login-oauth-app-account-settings-codexworld\" width=\"761\" height=\"331\" class=\"alignnone size-full wp-image-3409\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-account-settings-codexworld.png 761w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-account-settings-codexworld-300x130.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-account-settings-codexworld-200x87.png 200w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-account-settings-codexworld-346x150.png 346w\" sizes=\"auto, (max-width: 761px) 100vw, 761px\" \/><\/div>\n<\/li>\n<li>In the settings page, click <b>Developer settings<\/b> on the left sidebar.\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-developer-settings-codexworld.png\" alt=\"github-login-oauth-app-developer-settings-codexworld\" width=\"599\" height=\"173\" class=\"alignnone size-full wp-image-3410\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-developer-settings-codexworld.png 599w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-developer-settings-codexworld-300x87.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-developer-settings-codexworld-200x58.png 200w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-developer-settings-codexworld-346x100.png 346w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/div>\n<\/li>\n<li>In the left sidebar, click <b>OAuth Apps<\/b>. To create new OAuth app, click the <b>Register a new application<\/b>.\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-register-new-application-codexworld.png\" alt=\"github-login-oauth-register-new-application-codexworld\" width=\"908\" height=\"232\" class=\"alignnone size-full wp-image-3411\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-register-new-application-codexworld.png 908w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-register-new-application-codexworld-300x77.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-register-new-application-codexworld-768x196.png 768w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-register-new-application-codexworld-200x51.png 200w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-register-new-application-codexworld-346x88.png 346w\" sizes=\"auto, (max-width: 908px) 100vw, 908px\" \/><\/div>\n<\/li>\n<li>Enter all the necessary information (Application name, Homepage URL, Application description, and Authorization callback URL) to register your new OAuth application. Click <b>Register application<\/b> when you&#8217;re done.\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-create-oauth-api-application-codexworld.png\" alt=\"github-login-create-oauth-api-application-codexworld\" width=\"575\" height=\"576\" class=\"alignnone size-full wp-image-3412\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-create-oauth-api-application-codexworld.png 575w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-create-oauth-api-application-codexworld-150x150.png 150w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-create-oauth-api-application-codexworld-300x300.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-create-oauth-api-application-codexworld-200x200.png 200w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-create-oauth-api-application-codexworld-230x230.png 230w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/div>\n<\/li>\n<li><b>Client ID<\/b> and <b>Client Secret<\/b> of the application will be generated. Copy the GitHub OAuth details (Client ID and Client Secret) for later use in the script to access GitHub API.\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-api-client-id-secret-codexworld.png\" alt=\"github-login-oauth-app-api-client-id-secret-codexworld\" width=\"1003\" height=\"413\" class=\"alignnone size-full wp-image-3413\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-api-client-id-secret-codexworld.png 1003w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-api-client-id-secret-codexworld-300x124.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-api-client-id-secret-codexworld-768x316.png 768w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-api-client-id-secret-codexworld-200x82.png 200w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/github-login-oauth-app-api-client-id-secret-codexworld-346x142.png 346w\" sizes=\"auto, (max-width: 1003px) 100vw, 1003px\" \/><\/div>\n<\/li>\n<\/ul>\n<h2>Create Database Table<\/h2>\n<p>To store the user&#8217;s profile information from the GitHub account, a table needs to be created in the database. The following SQL creates a <code>users<\/code> table with some basic fields in the MySQL database.<\/p>\n<pre style=\"color: rgb(0, 0, 0);\"><span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">CREATE<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">TABLE<\/span> <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`users`<\/span> (\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(0, 134, 179);\">int<\/span>(<span class=\"hljs-number\" style=\"color: rgb(64, 160, 112);\">11<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span> AUTO_INCREMENT,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`oauth_provider`<\/span> enum(<span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">'github'<\/span>,<span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">'facebook'<\/span>,<span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">'google'<\/span>,<span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">'twitter'<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span> utf8_unicode_ci <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">DEFAULT<\/span> <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">'github'<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`oauth_uid`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(0, 134, 179);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(64, 160, 112);\">50<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span> utf8_unicode_ci <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`name`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(0, 134, 179);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(64, 160, 112);\">50<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span> utf8_unicode_ci <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`username`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(0, 134, 179);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(64, 160, 112);\">50<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span> utf8_unicode_ci <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`email`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(0, 134, 179);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(64, 160, 112);\">100<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span> utf8_unicode_ci <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`location`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(0, 134, 179);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(64, 160, 112);\">50<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span> utf8_unicode_ci <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`picture`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(0, 134, 179);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(64, 160, 112);\">255<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span> utf8_unicode_ci <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`link`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(0, 134, 179);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(64, 160, 112);\">255<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span> utf8_unicode_ci <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`created`<\/span> datetime <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">current_timestamp<\/span>(),\r\n  <span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`modified`<\/span> datetime <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(149, 65, 33);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">current_timestamp<\/span>(),\r\n  PRIMARY <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">KEY<\/span> (<span class=\"hljs-string\" style=\"color: rgb(33, 145, 97);\">`id`<\/span>)\r\n) <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">ENGINE<\/span>=<span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">InnoDB<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">CHARSET<\/span>=utf8 <span class=\"hljs-keyword\" style=\"color: rgb(149, 65, 33);\">COLLATE<\/span>=utf8_unicode_ci;<\/pre>\n<h2>Github OAuth Client for PHP (Github_OAuth_Client.php)<\/h2>\n<p>The Github_OAuth_Client class is a custom PHP library that handles GitHub REST API calls for OAuth-related requests.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><b>getAuthorizeURL()<\/b> &#8211; Generate URL to authorize with the Github account.<\/li>\n<li><b>getAccessToken()<\/b> &#8211; Exchange oauth code and get access token from Github OAuth API.<\/li>\n<li><b>apiRequest()<\/b> &#8211; Make an API call and retrieve the access token from Github OAuth API.<\/li>\n<li><b>getAuthenticatedUser()<\/b> &#8211; Execute the cURL request to get the authenticated user account data from Github User API.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/* <br \/>&nbsp;*&nbsp;Class&nbsp;Github_OAuth_Client <br \/>&nbsp;*&nbsp; <br \/>&nbsp;*&nbsp;Author:&nbsp;CodexWorld <br \/>&nbsp;*&nbsp;Author&nbsp;URL:&nbsp;https:\/\/www.codexworld.com <br \/>&nbsp;*&nbsp;Author&nbsp;Email:&nbsp;admin@codexworld.com <br \/>&nbsp;*&nbsp; <br \/>&nbsp;*&nbsp;The&nbsp;first&nbsp;PHP&nbsp;Library&nbsp;to&nbsp;support&nbsp;OAuth&nbsp;for&nbsp;GitHub&nbsp;REST&nbsp;API. <br \/>&nbsp;*\/ <br \/><\/span><span style=\"color: #007700\">class&nbsp;<\/span><span style=\"color: #0000BB\">Github_OAuth_Client<\/span><span style=\"color: #007700\">{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;<\/span><span style=\"color: #0000BB\">$authorizeURL&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"https:\/\/github.com\/login\/oauth\/authorize\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;<\/span><span style=\"color: #0000BB\">$tokenURL&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"https:\/\/github.com\/login\/oauth\/access_token\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;<\/span><span style=\"color: #0000BB\">$apiURLBase&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"https:\/\/api.github.com\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;<\/span><span style=\"color: #0000BB\">$clientID<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;<\/span><span style=\"color: #0000BB\">$clientSecret<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;<\/span><span style=\"color: #0000BB\">$redirectUri<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/** <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Construct&nbsp;object <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">__construct<\/span><span style=\"color: #007700\">(array&nbsp;<\/span><span style=\"color: #0000BB\">$config&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;[]){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clientID&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;isset(<\/span><span style=\"color: #0000BB\">$config<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'client_id'<\/span><span style=\"color: #007700\">])&nbsp;?&nbsp;<\/span><span style=\"color: #0000BB\">$config<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'client_id'<\/span><span style=\"color: #007700\">]&nbsp;:&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clientID<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(<\/span><span style=\"color: #DD0000\">'Required&nbsp;\"client_id\"&nbsp;key&nbsp;not&nbsp;supplied&nbsp;in&nbsp;config'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clientSecret&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;isset(<\/span><span style=\"color: #0000BB\">$config<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'client_secret'<\/span><span style=\"color: #007700\">])&nbsp;?&nbsp;<\/span><span style=\"color: #0000BB\">$config<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'client_secret'<\/span><span style=\"color: #007700\">]&nbsp;:&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clientSecret<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(<\/span><span style=\"color: #DD0000\">'Required&nbsp;\"client_secret\"&nbsp;key&nbsp;not&nbsp;supplied&nbsp;in&nbsp;config'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">redirectUri&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;isset(<\/span><span style=\"color: #0000BB\">$config<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'redirect_uri'<\/span><span style=\"color: #007700\">])&nbsp;?&nbsp;<\/span><span style=\"color: #0000BB\">$config<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'redirect_uri'<\/span><span style=\"color: #007700\">]&nbsp;:&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/** <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Get&nbsp;the&nbsp;authorize&nbsp;URL <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@returns&nbsp;a&nbsp;string <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">getAuthorizeURL<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$state<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">authorizeURL&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #DD0000\">'?'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">http_build_query<\/span><span style=\"color: #007700\">([ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'client_id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clientID<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'redirect_uri'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">redirectUri<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'state'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$state<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'scope'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'user:email' <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/** <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Exchange&nbsp;token&nbsp;and&nbsp;code&nbsp;for&nbsp;an&nbsp;access&nbsp;token <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">getAccessToken<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$state<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$oauth_code<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$token&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">self<\/span><span style=\"color: #007700\">::<\/span><span style=\"color: #0000BB\">apiRequest<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">tokenURL&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #DD0000\">'?'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">http_build_query<\/span><span style=\"color: #007700\">([ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'client_id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clientID<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'client_secret'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clientSecret<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'state'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$state<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'code'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$oauth_code <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">])); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">$token<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">access_token<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/** <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Make&nbsp;an&nbsp;API&nbsp;request <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;API&nbsp;results <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">apiRequest<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$access_token_url<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$apiURL&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">filter_var<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$access_token_url<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">FILTER_VALIDATE_URL<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$access_token_url<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">apiURLBase<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'user?access_token='<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$access_token_url<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$context&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">stream_context_create<\/span><span style=\"color: #007700\">([ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'http'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;[ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'user_agent'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'CodexWorld&nbsp;GitHub&nbsp;OAuth&nbsp;Login'<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'header'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Accept:&nbsp;application\/json' <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">] <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$response&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">file_get_contents<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$apiURL<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$context<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">$response&nbsp;<\/span><span style=\"color: #007700\">?&nbsp;<\/span><span style=\"color: #0000BB\">json_decode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$response<\/span><span style=\"color: #007700\">)&nbsp;:&nbsp;<\/span><span style=\"color: #0000BB\">$response<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/** <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Get&nbsp;the&nbsp;authenticated&nbsp;user <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@returns&nbsp;object <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">getAuthenticatedUser<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$access_token<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$apiURL&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">apiURLBase&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #DD0000\">'\/user'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ch&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">curl_init<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">curl_setopt<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">CURLOPT_URL<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$apiURL<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">curl_setopt<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">CURLOPT_RETURNTRANSFER<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">curl_setopt<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">CURLOPT_SSL_VERIFYPEER<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">FALSE<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">curl_setopt<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">CURLOPT_HTTPHEADER<\/span><span style=\"color: #007700\">,&nbsp;array(<\/span><span style=\"color: #DD0000\">'Content-Type:&nbsp;application\/json'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'Authorization:&nbsp;token&nbsp;'<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$access_token<\/span><span style=\"color: #007700\">)); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">curl_setopt<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">CURLOPT_USERAGENT<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'CodexWorld&nbsp;GitHub&nbsp;OAuth&nbsp;Login'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">curl_setopt<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">CURLOPT_CUSTOMREQUEST<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'GET'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$api_response&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">curl_exec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$http_code&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">curl_getinfo<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">CURLINFO_HTTP_CODE<\/span><span style=\"color: #007700\">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$http_code&nbsp;<\/span><span style=\"color: #007700\">!=&nbsp;<\/span><span style=\"color: #0000BB\">200<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(<\/span><span style=\"color: #0000BB\">curl_errno<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">))&nbsp;{&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$error_msg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">curl_error<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ch<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$error_msg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$api_response<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Exception<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'Error&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$http_code<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">':&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$error_msg<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">json_decode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$api_response<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>}<\/span><\/pre>\n<h2>User Class (User.class.php)<\/h2>\n<p>The User class handles the database related operations (fetch, insert, and update). Specify the database host (<code>$dbHost<\/code>), username (<code>$dbUsername<\/code>), password (<code>$dbPassword<\/code>), and name (<code>$dbName<\/code>) as per your MySQL database credentials.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><b>__construct()<\/b> &#8211; Connect to the database.<\/li>\n<li><b>checkUser()<\/b> &#8211; Check whether the user data already exists in the database. Update if user data exists, otherwise insert user&#8217;s profile data in the <code>users<\/code> table using PHP and MySQL.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/* <br \/>&nbsp;*&nbsp;User&nbsp;Class <br \/>&nbsp;*&nbsp;This&nbsp;class&nbsp;is&nbsp;used&nbsp;for&nbsp;database&nbsp;related&nbsp;(connect,&nbsp;insert,&nbsp;and&nbsp;update)&nbsp;operations <br \/>&nbsp;*&nbsp;@author&nbsp;&nbsp;&nbsp;&nbsp;CodexWorld.com <br \/>&nbsp;*&nbsp;@url&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http:\/\/www.codexworld.com <br \/>&nbsp;*&nbsp;@license&nbsp;&nbsp;&nbsp;&nbsp;http:\/\/www.codexworld.com\/license <br \/>&nbsp;*\/ <br \/> <br \/><\/span><span style=\"color: #007700\">class&nbsp;<\/span><span style=\"color: #0000BB\">User&nbsp;<\/span><span style=\"color: #007700\">{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$dbHost&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">DB_HOST<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$dbUsername&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">DB_USERNAME<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$dbPassword&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">DB_PASSWORD<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$dbName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">DB_NAME<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$userTbl&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">DB_USER_TBL<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">__construct<\/span><span style=\"color: #007700\">(){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!isset(<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Connect&nbsp;to&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$conn&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">mysqli<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">dbHost<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">dbUsername<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">dbPassword<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">dbName<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">connect_error<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(<\/span><span style=\"color: #DD0000\">\"Failed&nbsp;to&nbsp;connect&nbsp;with&nbsp;MySQL:&nbsp;\"&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">connect_error<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">checkUser<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array()){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;whether&nbsp;the&nbsp;user&nbsp;already&nbsp;exists&nbsp;in&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$checkQuery&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;*&nbsp;FROM&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">userTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;WHERE&nbsp;oauth_provider&nbsp;=&nbsp;'\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'oauth_provider'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\"'&nbsp;AND&nbsp;oauth_uid&nbsp;=&nbsp;'\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'oauth_uid'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\"'\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$checkResult&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$checkQuery<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;modified&nbsp;time&nbsp;to&nbsp;the&nbsp;data&nbsp;array <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">array_key_exists<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'modified'<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'modified'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">date<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Y-m-d&nbsp;H:i:s\"<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$checkResult<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">num_rows&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Prepare&nbsp;column&nbsp;and&nbsp;value&nbsp;format <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$colvalSet&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$i&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach(<\/span><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">as&nbsp;<\/span><span style=\"color: #0000BB\">$key<\/span><span style=\"color: #007700\">=&gt;<\/span><span style=\"color: #0000BB\">$val<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pre&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(<\/span><span style=\"color: #0000BB\">$i&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #DD0000\">',&nbsp;'<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$colvalSet&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #0000BB\">$pre<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$key<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"='\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">real_escape_string<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$val<\/span><span style=\"color: #007700\">).<\/span><span style=\"color: #DD0000\">\"'\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">++; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$whereSql&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"&nbsp;WHERE&nbsp;oauth_provider&nbsp;=&nbsp;'\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'oauth_provider'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\"'&nbsp;AND&nbsp;oauth_uid&nbsp;=&nbsp;'\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'oauth_uid'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\"'\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Update&nbsp;user&nbsp;data&nbsp;in&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$query&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"UPDATE&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">userTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;SET&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$colvalSet<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$whereSql<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$update&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$query<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;created&nbsp;time&nbsp;to&nbsp;the&nbsp;data&nbsp;array <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">array_key_exists<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'created'<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'created'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">date<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Y-m-d&nbsp;H:i:s\"<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Prepare&nbsp;column&nbsp;and&nbsp;value&nbsp;format <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$columns&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$values&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$i&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach(<\/span><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">as&nbsp;<\/span><span style=\"color: #0000BB\">$key<\/span><span style=\"color: #007700\">=&gt;<\/span><span style=\"color: #0000BB\">$val<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pre&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(<\/span><span style=\"color: #0000BB\">$i&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #DD0000\">',&nbsp;'<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$columns&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #0000BB\">$pre<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$key<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$values&nbsp;&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #0000BB\">$pre<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"'\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">real_escape_string<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$val<\/span><span style=\"color: #007700\">).<\/span><span style=\"color: #DD0000\">\"'\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">++; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Insert&nbsp;user&nbsp;data&nbsp;in&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$query&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"INSERT&nbsp;INTO&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">userTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;(\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$columns<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\")&nbsp;VALUES&nbsp;(\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$values<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\")\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$insert&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$query<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;user&nbsp;data&nbsp;from&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$checkQuery<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$userData&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">fetch_assoc<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Return&nbsp;user&nbsp;data <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">return&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>}<\/span><\/pre>\n<h2>Database and API Configuration (config.php)<\/h2>\n<p>In the <code>config.php<\/code> file, database settings and Github OAuth API configuration constant variables are defined.<\/p>\n<p><b>Database constants:<\/b><\/p>\n<ul class=\"bullet_disk_list\">\n<li>DB_HOST \u2013 Specify the database host.<\/li>\n<li>DB_USERNAME \u2013 Specify the database username.<\/li>\n<li>DB_PASSWORD \u2013 Specify the database password.<\/li>\n<li>DB_NAME \u2013 Specify the database name.<\/li>\n<li>DB_USER_TBL \u2013 Specify the table name where the user\u2019s account data will be stored.<\/li>\n<\/ul>\n<p><b>GitHub API constants:<\/b><\/p>\n<ul class=\"bullet_disk_list\">\n<li>CLIENT_ID \u2013 Specify the GitHub App Client ID.<\/li>\n<li>CLIENT_SECRET \u2013 Specify the GitHub App Client Secret.<\/li>\n<li>REDIRECT_URL \u2013 Specify the Authorization callback URL.<\/li>\n<\/ul>\n<p><b>Call GitHub API:<\/b><\/p>\n<ul class=\"bullet_disk_list\">\n<li>The Github OAuth PHP Client library is used to connect with Github API and working with OAuth client.<\/li>\n<li>Initialize Github_OAuth_Client class and pass Client ID, Secret, and Callback URL to connect with Github API and work with SDK.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Database&nbsp;configuration <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_HOST'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'MySQL_Database_Host'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_USERNAME'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'MySQL_Database_Username'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_PASSWORD'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'MySQL_Database_Password'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_NAME'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'MySQL_Database_Name'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_USER_TBL'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'users'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;GitHub&nbsp;API&nbsp;configuration <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'CLIENT_ID'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'Insert_App_Client_ID'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'CLIENT_SECRET'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'Insert_App_Client_Secret'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'REDIRECT_URL'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'Callback_URL'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Start&nbsp;session <br \/><\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">session_id<\/span><span style=\"color: #007700\">()){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">session_start<\/span><span style=\"color: #007700\">(); <br \/>} <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;Github&nbsp;client&nbsp;library <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'src\/Github_OAuth_Client.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Initialize&nbsp;Github&nbsp;OAuth&nbsp;client&nbsp;class <br \/><\/span><span style=\"color: #0000BB\">$gitClient&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Github_OAuth_Client<\/span><span style=\"color: #007700\">(array( <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'client_id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">CLIENT_ID<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'client_secret'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">CLIENT_SECRET<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'redirect_uri'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">REDIRECT_URL <br \/><\/span><span style=\"color: #007700\">)); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Try&nbsp;to&nbsp;get&nbsp;the&nbsp;access&nbsp;token <br \/><\/span><span style=\"color: #007700\">if(isset(<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'access_token'<\/span><span style=\"color: #007700\">])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$accessToken&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'access_token'<\/span><span style=\"color: #007700\">]; <br \/>}<\/span><\/pre>\n<h2>Login &#038; Fetch GitHub Profile Data (index.php)<\/h2>\n<p>If the user already logged in with the GitHub account, the profile information (account ID, name, username, email, location, profile picture, and profile link) will display, otherwise, GitHub login button will appear.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>If the access token already exists in the SESSION, the following happens:\n<ul>\n<li>The user profile data is retrieved from Github using <code>getAuthenticatedUser()<\/code> function of Github_OAuth_Client class.<\/li>\n<li>Pass profile data in the <code>checkUser()<\/code> function to insert or update user data in the database.<\/li>\n<li>Store the user account data in the SESSION.<\/li>\n<li>Show Github profile data to the user.<\/li>\n<\/ul>\n<\/li>\n<li>If code parameter exists in the query string of the URL, the following happens:\n<ul>\n<li>Verify the state to check whether it matches the stored state.<\/li>\n<li>Get access token using <code>getAccessToken()<\/code> function of Github_OAuth_Client class.<\/li>\n<li>Store access token in the SESSION.<\/li>\n<\/ul>\n<\/li>\n<li>Otherwise:\n<ul>\n<li>Generate an unguessable random string and store it in the SESSION.<\/li>\n<li>Get the OAuth URL using the <code>getAuthorizeURL()<\/code> function of Github_OAuth_Client class.<\/li>\n<li>Render a Github login button on the web page.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;configuration&nbsp;file <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'config.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;and&nbsp;initialize&nbsp;user&nbsp;class <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'User.class.php'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$user&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">User<\/span><span style=\"color: #007700\">(); <br \/> <br \/>if(isset(<\/span><span style=\"color: #0000BB\">$accessToken<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;the&nbsp;user&nbsp;profile&nbsp;data&nbsp;from&nbsp;Github <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUser&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$gitClient<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getAuthenticatedUser<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$accessToken<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Getting&nbsp;user&nbsp;profile&nbsp;details <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'oauth_uid'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">id<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">id<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'name'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">name<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">name<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'username'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">login<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">login<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'email'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">email<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">email<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'location'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">location<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">location<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'picture'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">avatar_url<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">avatar_url<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'link'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">html_url<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$gitUser<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">html_url<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Insert&nbsp;or&nbsp;update&nbsp;user&nbsp;data&nbsp;to&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'oauth_provider'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'github'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$userData&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$user<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">checkUser<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$gitUserData<\/span><span style=\"color: #007700\">); <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Storing&nbsp;user&nbsp;data&nbsp;in&nbsp;the&nbsp;session <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'userData'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">; <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Render&nbsp;Github&nbsp;profile&nbsp;data <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;h2&gt;GitHub&nbsp;Account&nbsp;Details&lt;\/h2&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;div&nbsp;class=\"ac-data\"&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;img&nbsp;src=\"'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'picture'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'\"&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;&lt;b&gt;ID:&lt;\/b&gt;&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'oauth_uid'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;&lt;b&gt;Name:&lt;\/b&gt;&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'name'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;&lt;b&gt;Login&nbsp;Username:&lt;\/b&gt;&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'username'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;&lt;b&gt;Email:&lt;\/b&gt;&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'email'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;&lt;b&gt;Location:&lt;\/b&gt;&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'location'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;&lt;b&gt;Profile&nbsp;Link:&lt;\/b&gt;&nbsp;&lt;a&nbsp;href=\"'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$userData<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'link'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'\"&nbsp;target=\"_blank\"&gt;Click&nbsp;to&nbsp;visit&nbsp;GitHub&nbsp;page&lt;\/a&gt;&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;Logout&nbsp;from&nbsp;&lt;a&nbsp;href=\"logout.php\"&gt;GitHub&lt;\/a&gt;&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;\/div&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;h3&nbsp;style=\"color:red\"&gt;Something&nbsp;went&nbsp;wrong,&nbsp;please&nbsp;try&nbsp;again!&lt;\/h3&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; <br \/>}elseif(isset(<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'code'<\/span><span style=\"color: #007700\">])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Verify&nbsp;the&nbsp;state&nbsp;matches&nbsp;the&nbsp;stored&nbsp;state <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'state'<\/span><span style=\"color: #007700\">]&nbsp;||&nbsp;<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'state'<\/span><span style=\"color: #007700\">]&nbsp;!=&nbsp;<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'state'<\/span><span style=\"color: #007700\">])&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Location:&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$_SERVER<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'PHP_SELF'<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Exchange&nbsp;the&nbsp;auth&nbsp;code&nbsp;for&nbsp;a&nbsp;token <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$accessToken&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$gitClient<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getAccessToken<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'state'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'code'<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'access_token'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$accessToken<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'Location:&nbsp;.\/'<\/span><span style=\"color: #007700\">); <br \/>}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Generate&nbsp;a&nbsp;random&nbsp;hash&nbsp;and&nbsp;store&nbsp;in&nbsp;the&nbsp;session&nbsp;for&nbsp;security <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'state'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">hash<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'sha256'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">microtime<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">TRUE<\/span><span style=\"color: #007700\">)&nbsp;.&nbsp;<\/span><span style=\"color: #0000BB\">rand<\/span><span style=\"color: #007700\">()&nbsp;.&nbsp;<\/span><span style=\"color: #0000BB\">$_SERVER<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'REMOTE_ADDR'<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Remove&nbsp;access&nbsp;token&nbsp;from&nbsp;the&nbsp;session <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">unset(<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'access_token'<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;the&nbsp;URL&nbsp;to&nbsp;authorize <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$authUrl&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$gitClient<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getAuthorizeURL<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'state'<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Render&nbsp;Github&nbsp;login&nbsp;button <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;a&nbsp;href=\"'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">htmlspecialchars<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$authUrl<\/span><span style=\"color: #007700\">).<\/span><span style=\"color: #DD0000\">'\"&gt;&lt;img&nbsp;src=\"images\/github-login.png\"&gt;&lt;\/a&gt;'<\/span><span style=\"color: #007700\">; <br \/>} <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n\r\n<span style=\"color: rgb(95, 94, 78);\"><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"container\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-comment\" style=\"color: rgb(108, 107, 90);\">&lt;!-- Display login button \/ GitHub profile information --&gt;<\/span>\r\n    <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$output<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span>&gt;<\/span><\/span>\r\n<\/pre>\n<h2>Logout (logout.php)<\/h2>\n<p>The <code>logout.php<\/code> file logs the user out from their Github account.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Unset all the SESSION variables (access_token, state, and userData) in PHP.<\/li>\n<li>Redirect the user to the homepage.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php<br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Start&nbsp;session<br \/><\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">session_id<\/span><span style=\"color: #007700\">()){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">session_start<\/span><span style=\"color: #007700\">();<br \/>}<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Remove&nbsp;access&nbsp;token&nbsp;and&nbsp;state&nbsp;from&nbsp;session<br \/><\/span><span style=\"color: #007700\">unset(<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'access_token'<\/span><span style=\"color: #007700\">]);<br \/>unset(<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'state'<\/span><span style=\"color: #007700\">]);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Remove&nbsp;user&nbsp;data&nbsp;from&nbsp;session<br \/><\/span><span style=\"color: #007700\">unset(<\/span><span style=\"color: #0000BB\">$_SESSION<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'userData'<\/span><span style=\"color: #007700\">]);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Redirect&nbsp;to&nbsp;the&nbsp;homepage<br \/><\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Location:index.php\"<\/span><span style=\"color: #007700\">);<br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/login-with-facebook-using-php\/\">Login with Facebook using PHP<\/a><\/span><\/p>\n<h2>Conclusion<\/h2>\n<p>Our <b>GitHub OAuth PHP<\/b> Library helps to integrate Login with Github in PHP. You can easily implement the Github OAuth login system in the web application. Also, the example code functionality can be extended as per your application needs. We also recommend you add other social accounts in the PHP login system for providing a user-friendly way to allow the user to log in to your website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GitHub provides a web-based hosting service for version control. It plays an important role in software and web development. Presently GitHub has over 28 million users from around the world. If you want to allow <\/p>\n","protected":false},"author":1,"featured_media":5020,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[250,84,39,14],"class_list":["post-3407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-api","tag-login","tag-oauth","tag-php","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Login with GitHub OAuth API using PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"GitHub OAuth Login using PHP - Integrate login system in PHP using GitHub OAuth API and store user&#039;s profile data in the MySQL database. Example code to implement Github authentication API using Github OAuth Client PHP library.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Login with GitHub OAuth API using PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"GitHub OAuth Login using PHP - Integrate login system in PHP using GitHub OAuth API and store user&#039;s profile data in the MySQL database. Example code to implement Github authentication API using Github OAuth Client PHP library.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-07T20:43:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-28T06:01:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/login-with-github-oauth-api-using-php-client-library-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Login with GitHub OAuth API using PHP\",\"datePublished\":\"2018-08-07T20:43:33+00:00\",\"dateModified\":\"2022-07-28T06:01:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/\"},\"wordCount\":915,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/login-with-github-oauth-api-using-php-client-library-codexworld.png\",\"keywords\":[\"API\",\"Login\",\"OAuth\",\"PHP\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/\",\"name\":\"Login with GitHub OAuth API using PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/login-with-github-oauth-api-using-php-client-library-codexworld.png\",\"datePublished\":\"2018-08-07T20:43:33+00:00\",\"dateModified\":\"2022-07-28T06:01:38+00:00\",\"description\":\"GitHub OAuth Login using PHP - Integrate login system in PHP using GitHub OAuth API and store user's profile data in the MySQL database. Example code to implement Github authentication API using Github OAuth Client PHP library.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/login-with-github-oauth-api-using-php-client-library-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/login-with-github-oauth-api-using-php-client-library-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"login-with-github-oauth-api-using-php-client-library-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/login-with-github-oauth-api-using-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Login with GitHub OAuth API using PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Login with GitHub OAuth API using PHP - CodexWorld","description":"GitHub OAuth Login using PHP - Integrate login system in PHP using GitHub OAuth API and store user's profile data in the MySQL database. Example code to implement Github authentication API using Github OAuth Client PHP library.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/","og_locale":"en_US","og_type":"article","og_title":"Login with GitHub OAuth API using PHP - CodexWorld","og_description":"GitHub OAuth Login using PHP - Integrate login system in PHP using GitHub OAuth API and store user's profile data in the MySQL database. Example code to implement Github authentication API using Github OAuth Client PHP library.","og_url":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2018-08-07T20:43:33+00:00","article_modified_time":"2022-07-28T06:01:38+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/login-with-github-oauth-api-using-php-client-library-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Login with GitHub OAuth API using PHP","datePublished":"2018-08-07T20:43:33+00:00","dateModified":"2022-07-28T06:01:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/"},"wordCount":915,"commentCount":5,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/login-with-github-oauth-api-using-php-client-library-codexworld.png","keywords":["API","Login","OAuth","PHP"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/","url":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/","name":"Login with GitHub OAuth API using PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/login-with-github-oauth-api-using-php-client-library-codexworld.png","datePublished":"2018-08-07T20:43:33+00:00","dateModified":"2022-07-28T06:01:38+00:00","description":"GitHub OAuth Login using PHP - Integrate login system in PHP using GitHub OAuth API and store user's profile data in the MySQL database. Example code to implement Github authentication API using Github OAuth Client PHP library.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/login-with-github-oauth-api-using-php-client-library-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/login-with-github-oauth-api-using-php-client-library-codexworld.png","width":1366,"height":768,"caption":"login-with-github-oauth-api-using-php-client-library-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/login-with-github-oauth-api-using-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Login with GitHub OAuth API using PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/08\/login-with-github-oauth-api-using-php-client-library-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-SX","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=3407"}],"version-history":[{"count":11,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3407\/revisions"}],"predecessor-version":[{"id":5019,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3407\/revisions\/5019"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5020"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=3407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=3407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=3407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}