Cleaner API.php, also gives bad response code now

This commit is contained in:
Mikael Nordfeldth 2014-02-23 19:18:51 +01:00
parent a5b366745f
commit 93a20ca158

31
API.php
View File

@ -34,10 +34,14 @@
· ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
include 'settings.php';
require_once('settings.php');
header("Content-type: application/json; charset=utf-8");
if(substr($apiroot,-1) != '/') { $apiroot .= '/'; } // add slash if missing
// add slash if missing
if(substr($apiroot,-1) != '/') {
$apiroot .= '/';
}
// post requests
if(isset($_POST['postRequest'])) {
@ -51,18 +55,9 @@ if(isset($_POST['postRequest'])) {
session_write_close(); // fix problem with curling to local
$reply=curl_exec($ch);
curl_close($ch);
session_start();
// force ssl on our domain
if($forcessl) {
$reply = str_replace('http://'.$siterootdomain,'https://'.$siterootdomain,$reply);
}
print $reply;
}
// get requests
elseif(isset($_POST['getRequest'])) {
} elseif(isset($_POST['getRequest'])) {
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $apiroot.$_POST['getRequest']);
@ -74,16 +69,20 @@ elseif(isset($_POST['getRequest'])) {
session_write_close();
$reply=curl_exec($ch);
curl_close($ch);
} else {
// 400 Bad request, since neither postRequest or getRequest were included
http_response_code(400);
exit;
}
session_start();
// force ssl on our domain
if($forcessl) {
$reply = str_replace('http:\/\/'.$siterootdomain,'https:\/\/'.$siterootdomain,$reply);
}
print $reply;
$reply = str_replace('http://'.$siterootdomain,'https://'.$siterootdomain, $reply);
}
echo $reply;
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·