Skip to content

Instantly share code, notes, and snippets.

@kopiro
Last active December 16, 2017 15:44
Show Gist options
  • Save kopiro/fd03dcff567b83f8758e to your computer and use it in GitHub Desktop.
Save kopiro/fd03dcff567b83f8758e to your computer and use it in GitHub Desktop.
WP Proxy in PHP for CORS
<?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