Facebook/Google API
- Form login with
Facebook/Google accounts
inPHP
- Clase redes Servidor
HTTP
conXAMPP
- How to enable
SSL (HTTPS protocol)
withXAMPP
in a localPHP
project
Set up config in modules/connect_db.php
:
$host = '';
$user_name = '';
$password = '';
$database = '';
$conn = mysqli_connect($host, $user_name, $password, $database);
if (!$conn) {
echo "Connection failed: ".mysqli_connect_error();
}
Create Virtual Host Name:
- Step 1: Access to
C:\xampp\apache\conf\httpd.conf
, and search for the code below, remove comment at line 2 if it is available
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
- Step 2: Access to
C:\xampp\apache\conf\extra\httpd-vhosts.conf
, and add the code below
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/api_login"
ServerName api_login.com
</VirtualHost>
Note, DocumentRoot is path to the project directory and ServerName is the link that leads you want to put on the website
- Step 3: Access to
C:\Windows\System32\drivers\etc\hosts
, and add your host
127.0.0.1 api_login.com
Note, host must have the same name as ServerName above
Configuring SSL HTTPS in XAMPP:
- Step 1: Create
crt
directory inC:\xampp\apache\
, then copycert.conf
,document.txt
andmake-cert.bat
in theSSL
directory of Project, and paste in there - Step 2: Open
cert.conf
, and correct the lines below
...
commonName_default = api_login.com
...
DNS.1 = api_login.com
- Step 3: Run
make-cert.bat
, then enter your domain, and press the enter key until the end
Note, folder "api_login.com" will be created
- Step 4: Run
server
in theapi_login.com
directory, and follow these steps below
Install Certificate -> Local Machine -> Next -> Place all certificates in the following store -> Browse -> Trusted Root Certification Authorities -> OK -> Next -> Finish -> OK
- Step 5: Copy the content of
document.txt
, and paste intoC:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/api_login"
ServerName api_login.com
ServerAlias *.api_login.com
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs/api_login"
ServerName api_login.com
ServerAlias *.api_login.com
SSLEngine on
SSLCertificateFile "crt/api_login.com/server.crt"
SSLCertificateKeyFile "crt/api_login.com/server.key"
</VirtualHost>
Create a Facebook login project
:
- Step 1: Visit Developers Facebook to create an account, then create a
facebook login application
- Step 2: Paste the path to your website created above into fields
Privacy Policy URL
andSite URL
- Step 3: Paste the path of
fb_callback.php
into filedValid OAuth Redirect URIs
in settings of your products - Step 4: Once done, go to settings and copy the
App ID
,App Secret
andAPI Version
, then paste intofb_config.php
inmodules/fb_config.php
as below
<?php
$fb = new Facebook\Facebook([
'app_id' => '012345678987654',
'app_secret' => 'password',
'default_graph_version' => 'v10.0'
]);
?>
Create a Google login project
:
- Step 1: Visit Google Cloud Platform to create an account, then create a
google login application
- Step 2: Once done, go to credentials and copy the
Client ID
andClient secret
, then paste intogg_source.php
inmodules/gg_source.php
as below
<?php
...
$client_id = '12312312-v2131938712093791';
$client_secret = 'kj1231298casdjkh1';
$redirect_uri = 'https://api_login.com';
...
?>
Index:
https://api_login.com/