-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
33 lines (25 loc) · 837 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace Amazon;
require_once('vendor/autoload.php');
// Get the client ip address
$ip = $_SERVER['REMOTE_ADDR'];
$uri = $_SERVER['REQUEST_URI'];
use Amazon\Service\AmazonUrlBuilder;
use Amazon\DB\Db;
// get the config
$db = new \SQLite3(__DIR__ . "/amazonRedirect.db");
$testMode = $db->querySingle("SELECT value FROM config WHERE key = 'testMode'");
// if admin, redirect, move all this when tested
$request = filter_var(parse_url($uri,PHP_URL_PATH),FILTER_SANITIZE_URL);
//now remove amazon-url or subdir thing if exists
if (!empty($urlPrefix) ) {
$path = substr($request,strlen($urlPrefix));
}
$urlbuilder = new Service\AmazonUrlBuilder();
$theurl = $urlbuilder->getLocalKindleUrl($ip);
if($testMode === 'false'){
print $theurl . ' -  ' . $ip;
} else {
header("Location: $theurl");
exit();
}