0
0
This repository has been archived on 2020-11-15. You can view files and clone it, but cannot push or open issues or pull requests.
OpenShorte.old/lib/php/go.php
Bryan Pedini 18dc9b18d3
Website refactoring
Moved PHP files to "lib" folder
Moved Javascript files to "lib" folder
Moved login page inline CSS to "login.css"
Moved database functions to class "Database"
Removed the html template, compensated with a direct HTML code inside PHP "else" statement
2019-03-25 11:27:37 +01:00

58 lines
2.1 KiB
PHP

<?php
if ( isset ( $request [ 1 ] ) ) {
$link_id = $request [ 1 ];
if ( ! ctype_digit ( $link_id ) ) {
die ( "You can't be forwarded to a non numerical URL link ID. If you think this is incorrect, please send an email to shorte@dev.bryanpedini.it with this URL: https://sh.bjphoster.com/?go=" . $link_id . " for more investigations" );
}
$link_id = (int) $link_id;
$database = new Database ( $config [ 'db' ] );
$database->connect ( );
$database->prepare ( "SELECT links.URL FROM links WHERE links.ID = ?" );
$parameters = [
[ "i" ],
[ &$link_id ],
];
$database->bind ( $parameters );
$database->execute ( );
$result = $database->get_result ( );
$row = $result->fetch_assoc ( );
if ( ! $row ) {
http_response_code ( 404 );
include ( $config [ 'installation_path' ] . '/lib/errors/404.html' );
exit;
}
else {
?>
<!DOCTYPE html>
<html>
<head>
<title id="title">Redirect in 5 seconds</title>
<link href="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/favicon.ico" rel="icon" type="image/x-icon">
</head>
<body>
<center>
<h1>You will be redirected to <?=$row['URL']?> in <span id="body-timeout">5</span></h1>
</center>
<script>
window.onload = function() {
var seconds = 5;
function update_timeout (interval) {
document.getElementById("title").innerHTML = "Redirect in "+seconds+" seconds";
document.getElementById("body-timeout").innerHTML = seconds;
if (seconds == 0) {
window.location.href = "<?=$row['URL']?>";
clearInterval (interval);
}
}
interval = setInterval (function() {update_timeout(interval); seconds = seconds - 1;}, 1000);
}
</script>
</body>
</html>
<?php
}
}
else {
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) );
}
?>