$_GET['access_token'],
'client_id' => $CLIENT_ID
);
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url); // URL to submit the POST request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string instead of outputting it directly
curl_setopt($ch, CURLOPT_POST, true); // Set the request type to POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); // Set the POST data
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Ignore SSL certificate verification (not recommended in production)
$response = curl_exec($ch);
if ($response === false) {
echo "cURL error: " . curl_error($ch);
header('Location: /demo-login');
}
curl_close($ch);
$json_data = json_decode($response,true);
if($json_data['status'] != 200) {
header('Location: /demo-login');
}
$country_code = $json_data['country_code'];
$phone_no = $json_data['phone_no'];
$ph_email_jwt = $json_data['ph_email_jwt'];
setcookie('ph_email_jwt', $ph_email_jwt, time() + (86400 * 180), "/"); // 180 days
// Register User: As the user phone number has been verified successfully. If user corrosponding to this verified mobile number does not exist in your user table then register the user by creating a row in user table. If user already exists then simply continue to the next step.
// Send Email: We reccomend you to send welcome email to the user.
//curl --location --request POST "https://api.phone.email/v1/sendmail" --ssl-no-revoke --header "Content-Type: application/json" --data-raw "{'apiKey':'API_KEY','fromCountryCode':'XXX','fromPhoneNo':'XXXXXXXXXX', 'toCountrycode':'XX','toPhoneNo':'XXXXXXXXXX','subject': 'Welcome to YOUR_BUSINESS_NAME','tinyFlag':true,'messageBody':'V2VsY29tZSB0byB5b3VyIEJVU0lORVNTX05BTUU='}"
// Create Session: Store verified user phone number in session variable.
// Redirect: Redirect user to the page of your choice as the user has successfully logged in.
// Handle Logout (Optional): You can create logout button on your website as required.In the event of logout you must clear delete ph_email_jwt cookie and clear your session variables. To delete cookie simply set it to blank -> setcookie("ph_email_jwt", "", time()-3600);
?>