Skip to content

Instantly share code, notes, and snippets.

@heriniaina
Last active January 14, 2024 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heriniaina/6a70a50e27d9a20d2cdc463b5bdd01bf to your computer and use it in GitHub Desktop.
Save heriniaina/6a70a50e27d9a20d2cdc463b5bdd01bf to your computer and use it in GitHub Desktop.
proxy php to forward request
<?php
// Allow requests from any origin
header("Access-Control-Allow-Origin: *");
// Replace 'YOUR_API_ENDPOINT' with the actual API endpoint
$apiEndpoint = 'https://sandipapi.onrender.com/gpt';
// Get the prompt from the query parameters
$prompt = isset($_GET['prompt']) ? $_GET['prompt'] : '';
// Construct the API request URL
$apiRequestUrl = $apiEndpoint . '?prompt=' . urlencode($prompt);
// Make the request to the external API
$response = file_get_contents($apiRequestUrl);
// Output the response as JSON
header('Content-Type: application/json');
echo json_encode(['response' => $response]);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment