You've already forked OpenShorte.old
							
							Moved database function in class "Database"; Corrected database-using webpages accordingly; Moved config file from PHP to JSON with more config variables; Corrected login page redirection on wrong username or password.
		
			
				
	
	
		
			32 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			1.2 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 ( 'errors/404.html' );
 | 
						|
            exit;
 | 
						|
        }
 | 
						|
        else {
 | 
						|
            include ( 'templates/redirect.html' );
 | 
						|
            echo ( '<script>var my_location = "' . $row [ 'URL' ] . '";</script>' );
 | 
						|
        }
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) );
 | 
						|
    }
 | 
						|
?>
 |