How can PHP be used to integrate authentication systems like PayPal for user verification on a web portal?

To integrate authentication systems like PayPal for user verification on a web portal using PHP, you can utilize PayPal's API to verify user credentials and authenticate users before granting access to the portal. This can be achieved by sending requests to PayPal's API endpoints with user credentials and processing the response to determine if the user is authenticated.

<?php
// Set up PayPal API credentials
$clientId = 'YOUR_CLIENT_ID';
$clientSecret = 'YOUR_CLIENT_SECRET';

// Set up PayPal API endpoint
$apiEndpoint = 'https://api.paypal.com/v1/oauth2/token';

// Set up user credentials for verification
$userEmail = 'user@example.com';
$userPassword = 'password123';

// Make a request to PayPal API to authenticate user
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiEndpoint);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=password&username=' . $userEmail . '&password=' . $userPassword);
curl_setopt($ch, CURLOPT_USERPWD, $clientId . ':' . $clientSecret);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
$response = json_decode($result, true);

// Check if user is authenticated
if(isset($response['access_token'])) {
    // User is authenticated, grant access to web portal
    echo 'User authenticated successfully!';
} else {
    // User authentication failed
    echo 'User authentication failed. Please try again.';
}

curl_close($ch);
?>