Erik's Link Shortener
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
850 B

<?php
$dbname = "els.txt";
$notfound = "notfound.html";
$error = "error.html";
if ( !file_exists( $dbname ) ) {
header( $_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500 );
echo file_get_contents( $error );
exit;
}
if ( !isset( $_GET[ 'redir' ] ) ) {
header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Page not found', true, 500 );
echo file_get_contents( $notfound );
exit;
}
$dbc = file_get_contents( $dbname );
foreach ( explode( "\n", $dbc ) as $line ) {
if ( substr( $line, 0, 1 ) === '#' ) {
continue;
}
$parts = explode( ' ', trim( $line ) );
if ( count( $parts ) === 2 && $parts[ 0 ] === $_GET[ 'redir' ] ) {
header( 'Location: ' . $parts[ 1 ] );
exit;
}
}
header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Page not found', true, 404 );
echo file_get_contents( $notfound );
exit;