0
0

Minor changes

Moved config into $GLOBALS
Moved request_uri into $GLOBALS
Modified all files accordingly
Modified logout page for future improvements (not deleting the entire $_SESSION)
Fixed LICENSEs, moved LICENSE for PHP files in /lib/php subfolder instead of /lib
This commit is contained in:
Bryan
2019-04-06 11:57:35 +02:00
parent 18dc9b18d3
commit 81d21c311f
11 changed files with 30 additions and 29 deletions

View File

@@ -2,10 +2,10 @@
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
}
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
$database->connect ( );
if ( isset ( $_POST [ 'url' ] ) ) {
$url = $_POST [ 'url' ];
$database = new Database ( $config [ 'db' ] );
$database->connect ( );
$database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
$parameters = [
[ "s" ],
@@ -13,7 +13,7 @@
];
$database->bind ( $parameters );
$database->execute ( );
$database->prepare ( "SELECT COUNT( links.ID ) as `count` FROM links;");
$database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;");
$database->execute ( );
$result = $database->get_result ( );
$row = $result->fetch_assoc ( );
@@ -21,13 +21,12 @@
$response = [
'status' => 200,
'message' => 'URL inserted correctly.',
'new_id' => $row [ 'count' ],
'last_insert' => $row [ 'last' ],
];
echo ( json_encode ( $response ) );
exit;
}
else {
$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 ( );
@@ -62,4 +61,3 @@
</html>
<?php
}
?>