Created
May 20, 2013 04:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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