Skip to content

Instantly share code, notes, and snippets.

@phette23
Created August 29, 2016 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phette23/754fb9b4bbd07a352692999066f73554 to your computer and use it in GitHub Desktop.
Save phette23/754fb9b4bbd07a352692999066f73554 to your computer and use it in GitHub Desktop.
proxy ByWater's Coce cover image cache server (for use on an HTTPS domain)
<?php
// this proxies ByWater Solutions' "COCE" cover image service
// which does not work over HTTPS, so fill in our libraries.cca.edu
// server as our COCE server & it intercepts requests, sending along
// data from ByWater's COCE server
// we're sending JS
header( 'Content-Type:application/javascript; charset=utf-8' );
// requests look like
// coce.bywatersolutions.com/cover?id=0231081596,0816614024&provider=aws,gb,ol
// &callback=jQuery17209698950295937665_1468611400913&_=1468611401160
$id = $_GET['id'];
$provider = $_GET['provider'];
function get_coce ($id, $provider) {
// return only JSON, no need for callback wrapper
return file_get_contents(
'http://coce.bywatersolutions.com/cover?id=' . $id . '&provider=' . $provider
);
}
$json = get_coce($id, $provider);
// we sometimes get an empty response on first try, attempt again
if ($json = '{}') {
$json = get_coce($id, $provider);
}
// if we have callpack param, wrap it around JSON, otherwise send just JSON
if (isset($_GET['callback'])) {
echo $_GET['callback'] . '(' . $json . ')';
} else {
echo $json;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment