Last active
December 16, 2017 15:44
-
-
Save kopiro/fd03dcff567b83f8758e to your computer and use it in GitHub Desktop.
WP Proxy in PHP for CORS
This file contains hidden or 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 | |
if (preg_match("/^\/proxy\/(.+)$/", $_SERVER['REQUEST_URI'], $match)) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "http://api.com/" . $match[1]); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'Proxy'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 5); | |
die(curl_exec($ch)); | |
} | |
define('WORDPRESS_DIR', __DIR__ . '/wp'); | |
define('WP_STARTER', WORDPRESS_DIR . '/wp-blog-header.php'); | |
require WP_STARTER; | |
/* | |
Point all your external requests to http://site.com/proxy/collection?filter=1 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment