You've already forked OpenShorte.old
							
							Refactored database, refactored config file, corrected login redirection
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.
This commit is contained in:
		@@ -4,17 +4,18 @@
 | 
			
		||||
    }
 | 
			
		||||
    if ( isset ( $_POST [ 'url' ] ) ) {
 | 
			
		||||
        $url = $_POST [ 'url' ];
 | 
			
		||||
        $db_connection = db_connect ( );
 | 
			
		||||
        $statement = db_prepare ( $db_connection, "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
 | 
			
		||||
        $database = new Database ( $config [ 'db' ] );
 | 
			
		||||
        $database->connect ( );
 | 
			
		||||
        $database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
 | 
			
		||||
        $parameters = [
 | 
			
		||||
            [ "s" ],
 | 
			
		||||
            [ &$url ],
 | 
			
		||||
        ];
 | 
			
		||||
        db_bind ( $statement, $parameters );
 | 
			
		||||
        db_execute ( $statement );
 | 
			
		||||
        $statement = db_prepare ( $db_connection, "SELECT COUNT( links.ID ) as `count` FROM links;");
 | 
			
		||||
        db_execute ( $statement );
 | 
			
		||||
        $result = $statement->get_result ( );
 | 
			
		||||
        $database->bind ( $parameters );
 | 
			
		||||
        $database->execute ( );
 | 
			
		||||
        $database->prepare ( "SELECT COUNT( links.ID ) as `count` FROM links;");
 | 
			
		||||
        $database->execute ( );
 | 
			
		||||
        $result = $database->get_result ( );
 | 
			
		||||
        $row = $result->fetch_assoc ( );
 | 
			
		||||
        header ( 'Content-Type: application/json' );
 | 
			
		||||
        $response = [
 | 
			
		||||
@@ -25,10 +26,11 @@
 | 
			
		||||
        echo ( json_encode ( $response ) );
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        $db_connection = db_connect ( );
 | 
			
		||||
        $statement = db_prepare ( $db_connection, "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] );
 | 
			
		||||
        db_execute ( $statement );
 | 
			
		||||
        $result = $statement->get_result ( );
 | 
			
		||||
        $database = new Database ( $config [ 'db' ] );
 | 
			
		||||
        $database->connect ( );
 | 
			
		||||
        $database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] );
 | 
			
		||||
        $database->execute ( );
 | 
			
		||||
        $result = $database->get_result ( );
 | 
			
		||||
        $row = $result->fetch_assoc ( );
 | 
			
		||||
?>
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user