pastebin

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 9a18320ffe4103a158b64c39a345f16b20b329b6
parent 444ce2efb7009fe3ecbe58013b0d29ccde2d8ae5
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Fri Dec 20 11:43:30 2013

Added config file

Diffstat:
 config.json |  8 ++++++++
 index.php   | 11 ++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/config.json b/config.json @@ -0,0 +1,8 @@ +{ + "db_hostname": "localhost", + "db_username": "root", + "db_password": "", + "db_name": "pastebin", + "maintemplate": "./default.page", + "pastetemplate": "./paste.page" +}+ \ No newline at end of file diff --git a/index.php b/index.php @@ -1,9 +1,10 @@ <?php +$config = json_decode(file_get_contents("./config.json"),TRUE); if (empty($_POST) && empty($_GET)) { - echo str_replace("%text%", "", file_get_contents("./default.page")); + echo str_replace("%text%", "", file_get_contents($config["maintemplate"])); } else if (!empty($_GET)) { if (isset($_GET['id'])) { - $con = mysqli_connect("localhost","nanner","6174sql","pastebin"); + $con = mysqli_connect($config['db_hostname'],$config['db_username'],$config['db_password'],$config['db_name']); $paste = mysqli_query($con,"SELECT paste, title FROM pastes WHERE id= ".mysql_real_escape_string($_GET['id'])); $pasteContent = mysqli_fetch_array($paste); $content = "<div class='text'>\n <ol>\n"; @@ -28,7 +29,7 @@ if (empty($_POST) && empty($_GET)) { str_replace("%lineNumberWidth%",$lineNumberWidth, str_replace("%content%","$content",file_get_contents("paste.page"))))); } else if (isset($_GET['new'])) { - $con = mysqli_connect("localhost","nanner","6174sql","pastebin"); + $con = mysqli_connect($config['db_hostname'],$config['db_username'],$config['db_password'],$config['db_name']); $paste = mysqli_query($con,"SELECT paste FROM pastes WHERE id= ".mysql_real_escape_string($_GET['new'])); $pasteContent = mysqli_fetch_array($paste); $content = ""; @@ -45,7 +46,7 @@ if (empty($_POST) && empty($_GET)) { } } else { if (isset($_POST['paste']) && $_POST['title']) { - $con = mysqli_connect("localhost","nanner","6174sql","pastebin"); + $con = mysqli_connect($config['db_hostname'],$config['db_username'],$config['db_password'],$config['db_name']); $paste = mysql_real_escape_string($_POST['paste']); $title = mysql_real_escape_string($_POST['title']); $query = "INSERT INTO pastes ( paste, title ) VALUES ( '$paste' , '$title' );"; @@ -54,7 +55,7 @@ if (empty($_POST) && empty($_GET)) { } $id = mysqli_insert_id($con); mysqli_close($con); - header("Location: /$id"); + header("Location: /p/$id"); } else { echo "What did you do!?!??!"; }