Are there any best practices for handling cross-origin requests securely in PHP?

Cross-origin requests can pose security risks if not handled properly. To securely handle cross-origin requests in PHP, you can use the header function to set appropriate CORS headers. This includes setting Access-Control-Allow-Origin to restrict which origins can access your resources, Access-Control-Allow-Methods to specify allowed HTTP methods, and Access-Control-Allow-Headers to specify allowed headers.

header("Access-Control-Allow-Origin: https://example.com");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");