Implement basic service
This commit is contained in:
parent
5077afac20
commit
704fe11f4c
24
LICENSE
24
LICENSE
|
@ -1,19 +1,21 @@
|
||||||
MIT License Copyright (c) <year> <copyright holders>
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 Felix W. Dekker
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is furnished
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice (including the next
|
The above copyright notice and this permission notice shall be included in all
|
||||||
paragraph) shall be included in all copies or substantial portions of the
|
copies or substantial portions of the Software.
|
||||||
Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
|
||||||
|
|
||||||
|
|
||||||
|
$db = new SQLite3(".links.db", SQLITE3_OPEN_READWRITE);
|
||||||
|
$stmt = $db->prepare("SELECT * FROM links WHERE path = :path;");
|
||||||
|
$stmt->bindValue(":path", $path);
|
||||||
|
$result = $stmt->execute()->fetchArray(SQLITE3_ASSOC);
|
||||||
|
|
||||||
|
$stmt = $db->prepare("UPDATE links SET visits = visits + 1, last_used = CURRENT_TIMESTAMP WHERE path = :path;");
|
||||||
|
$stmt->bindValue(":path", $path);
|
||||||
|
$stmt->execute();
|
||||||
|
$db->close();
|
||||||
|
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$target = $result["target"];
|
||||||
|
header("Location: {$target}");
|
||||||
|
// print("Redirecting to {$target}");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print("No redirect necessary");
|
Loading…
Reference in New Issue