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

16
lib/php/LICENSE Normal file
View File

@@ -0,0 +1,16 @@
Copyright © 2019 - Bryan Pedini
Every file within this folder and it's subfolders is provided
with the website for the correct work of the website itself,
is provided AS IS, comes with NO WARRANTY of scope or
working purposes, and is proprietary software.
Such this code may not be copied without explicit permission from
myself only, this code may not be modified within the website,
you may not copy, edit, share, clone or do anything else but
use the code as is, without explicit permission to do so.
Such permissions can be requested at copyright@bryanpedini.it
No permissions to do anything against this license is given
without an explicit and valid motivation to do so, so please
don't email me asking any permission without providing a valid reason.

View File

@@ -5,7 +5,7 @@
private $statement;
public function __construct ( $config ) {
if ( $config ) {
if ( $config && $config [ 'host' ] && $config [ 'username' ] && $config [ 'password' ] && $config [ 'name' ] && $config [ 'port' ] ) {
$this->config = $config;
}
else {
@@ -41,4 +41,4 @@
public function get_result ( ) : MySQLi_result {
return $this->statement->get_result ( );
}
}
}

View File

@@ -1,4 +1,12 @@
<?php
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
$database->connect ( );
if ( isset ( $_POST [ 'forgot_email' ] ) ) {
//...
}
elseif ( isset ( $_POST [ 'forgot_username' ] ) ) {
//...
}
?>
<!DOCTYPE HTML>
<html>

View File

@@ -1,11 +1,11 @@
<?php
if ( isset ( $request [ 1 ] ) ) {
$link_id = $request [ 1 ];
if ( isset ( $GLOBALS [ 'request_uri' ] [ 1 ] ) ) {
$link_id = $GLOBALS [ 'request_uri' ] [ 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 = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
$database->connect ( );
$database->prepare ( "SELECT links.URL FROM links WHERE links.ID = ?" );
$parameters = [
@@ -18,7 +18,7 @@
$row = $result->fetch_assoc ( );
if ( ! $row ) {
http_response_code ( 404 );
include ( $config [ 'installation_path' ] . '/lib/errors/404.html' );
include ( $GLOBALS [ 'config' ] [ 'installation_path' ] . '/lib/errors/404.html' );
exit;
}
else {
@@ -55,4 +55,3 @@
else {
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) );
}
?>

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
}
?>

View File

@@ -23,6 +23,7 @@
$row = $result->fetch_assoc ( );
if ( ! $row ) {
header ( 'Content-Type: application/json' );
http_response_code ( 401 );
$response = [
'status' => 401,
'error_message' => 'Username or password not correct.',
@@ -81,4 +82,3 @@
</html>
<?php
}
?>

View File

@@ -1,5 +1,3 @@
<?php
$_SESSION = array ( );
session_destroy ( );
$_SESSION [ 'user_id' ] = NULL;
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/" );
?>