Skip to content

Instantly share code, notes, and snippets.

@iandundas
Created May 20, 2013 04:39
Show Gist options
  • Save iandundas/5610450 to your computer and use it in GitHub Desktop.
Save iandundas/5610450 to your computer and use it in GitHub Desktop.
PHP: Relay POST and GET requests to a new URL, and output the result
<?php
// was used when API address moved but apps were live on app store.
$ch = curl_init();
$path = $_SERVER['REQUEST_URI'];
$path = str_replace('/api/index.php','',$path);
$path = str_replace('/api/','/',$path);
/* Forward POST on to new API: */
curl_setopt($ch, CURLOPT_URL, 'https://[youraddress.com]/api.php'.$path);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment