2019-03-18 10:23:48 +00:00
< ? php
2019-07-18 09:38:03 +00:00
if ( isset ( $request_uri [ 1 ] ) ) {
$link_id = $request_uri [ 1 ];
2019-03-18 10:23:48 +00:00
if ( ! ctype_digit ( $link_id ) ) {
2019-04-11 10:54:14 +00:00
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 " );
2019-03-18 10:23:48 +00:00
}
$link_id = ( int ) $link_id ;
2019-07-18 09:38:03 +00:00
$database = new Database ( $config [ 'db' ] );
2019-03-21 11:07:23 +00:00
$database -> connect ( );
2019-05-29 17:27:41 +00:00
$database -> prepare ( " SELECT links.URL FROM links WHERE links.ID = :link_id " );
$database -> bind ( [ ':link_id' => $link_id ] );
2019-03-21 11:07:23 +00:00
$database -> execute ( );
$result = $database -> get_result ( );
2019-05-29 17:27:41 +00:00
if ( $result -> rowCount ( ) == 0 ) {
2019-03-18 10:23:48 +00:00
http_response_code ( 404 );
2019-07-18 09:38:03 +00:00
include ( $config [ 'installation_path' ] . '/lib/errors/404.html' );
2019-03-18 10:23:48 +00:00
exit ;
}
else {
2019-05-29 17:27:41 +00:00
$row = $result -> fetchAll ( ) [ 0 ];
2019-03-25 10:27:37 +00:00
?>
<! DOCTYPE html >
< html >
2019-07-17 08:37:44 +00:00
2019-03-25 10:27:37 +00:00
< head >
2019-05-29 17:01:38 +00:00
< meta charset = " UTF-8 " >
2019-08-10 08:55:55 +00:00
< meta description = " Redirecting to <?= $row['URL'] ?> " >
2019-07-18 09:38:03 +00:00
< link href = " <?= $config['installation_path'] ?>/favicon.ico " rel = " icon " type = " image/x-icon " >
2019-07-24 13:17:59 +00:00
< link href = " <?= $config['installation_path'] ?>/lib/css/main.css " rel = " stylesheet " >
< title > Redirecting to < ? = $row [ 'URL' ] ?> | <?=$config['website_name']?></title>
2019-03-25 10:27:37 +00:00
</ head >
2019-07-17 08:37:44 +00:00
2019-03-25 10:27:37 +00:00
< body >
< center >
< h1 > You will be redirected to < ? = $row [ 'URL' ] ?> in <span id="body-timeout">5</span></h1>
</ center >
< script >
2019-07-17 08:37:44 +00:00
window . onload = function () {
var seconds = 5 ;
function update_timeout ( interval ) {
document . getElementById ( " body-timeout " ) . innerHTML = seconds ;
if ( seconds == 0 ) {
window . location . href = " <?= $row['URL'] ?> " ;
clearInterval ( interval );
2019-03-25 10:27:37 +00:00
}
}
2019-07-17 08:37:44 +00:00
interval = setInterval ( function () {
update_timeout ( interval );
seconds = seconds - 1 ;
}, 1000 );
}
2019-03-25 10:27:37 +00:00
</ script >
</ body >
2019-07-17 08:37:44 +00:00
2019-03-25 10:27:37 +00:00
</ html >
< ? php
2019-03-18 10:23:48 +00:00
}
}
else {
header ( " Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0 , - 10 ) );
}