In what ways can SSL encryption be implemented in PHP scripts to enhance security during data transmission between a client app and server?
SSL encryption can be implemented in PHP scripts by using the cURL library to send HTTPS requests to the server. This ensures that data transmitted between the client app and server is encrypted and secure. By verifying the SSL certificate of the server, you can also prevent man-in-the-middle attacks.
// Initialize cURL session
$ch = curl_init();
// Set the URL to send the request to
curl_setopt($ch, CURLOPT_URL, 'https://example.com/api');
// Verify the SSL certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// Execute the request and fetch the response
$response = curl_exec($ch);
// Close the cURL session
curl_close($ch);
// Process the response data
echo $response;