Fix sent header error

Fix sent header error.
This commit is contained in:
Danang Probo Sayekti 2014-01-20 20:47:07 +07:00
commit 97a678fc64
7 changed files with 172 additions and 135 deletions

View file

@ -1,18 +0,0 @@
<div id="login">
<?php if (login()) { ?>
<div class="nav">
<a href="<?php echo config('site.url');?>/admin">Admin</a>
<a href="includes/create_post.php">Create post</a>
<a href="includes/logout.php">Logout</a>
<span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span>
</div>
<?php include 'includes/post_list.php';?>
<?php } else {?>
<?php include 'includes/login.php';?>
<?php } ?>
</div>

View file

@ -1,9 +1,30 @@
<?php <?php
// Change this to your timezone // Change this to your timezone
date_default_timezone_set('Asia/Jakarta'); date_default_timezone_set('Asia/Jakarta');
require '../../system/includes/dispatch.php'; require '../../system/includes/dispatch.php';
config('source', '../../admin/config.ini'); config('source', '../../admin/config.ini');
include '../includes/session.php'; include '../includes/session.php';
if(isset($_POST['submit'])) {
$post_date = date('Y-m-d-H');
$post_tag = $_POST['tag'];
$post_url = $_POST['url'];
$post_content = $_POST['content'];
}
if(!empty($post_tag) && !empty($post_url) && !empty($post_content)) {
$user = $_SESSION['user'];
$filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
$dir = '../../content/' . $user. '/blog/';
if(is_dir($dir)) {
file_put_contents($dir . $filename, print_r($post_content, true));
}
else {
mkdir($dir, 0777, true);
file_put_contents($dir . $filename, print_r($post_content, true));
}
header('location: ../index.php');
}
if (login()) {
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -18,37 +39,12 @@ include '../includes/session.php';
<body> <body>
<div class="wrapper-outer"> <div class="wrapper-outer">
<div class="wrapper-inner"> <div class="wrapper-inner">
<?php if (login()) { ?>
<div class="nav"> <div class="nav">
<a href="<?php echo config('site.url');?>/admin">Admin</a> <a href="<?php echo config('site.url');?>" target="_blank">Home</a> |
<a href="../includes/logout.php">Logout</a> <a href="<?php echo config('site.url');?>/admin">Admin</a> |
<a href="../includes/logout.php">Logout</a> |
<span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span> <span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span>
</div> </div>
<?php
if(isset($_POST['submit'])) {
$post_date = date('Y-m-d-H');
$post_tag = $_POST['tag'];
$post_url = $_POST['url'];
$post_content = $_POST['content'];
}
if(!empty($post_tag) && !empty($post_url) && !empty($post_content)) {
$user = $_SESSION['user'];
$filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
$dir = '../../content/' . $user. '/blog/';
if(is_dir($dir)) {
file_put_contents($dir . $filename, print_r($post_content, true));
}
else {
mkdir($dir, 0777, true);
file_put_contents($dir . $filename, print_r($post_content, true));
}
header('location: ../index.php');
}
?>
<?php } else {?>
<?php header('location: ../index.php');?>
<?php } ?>
<div class="wmd-panel"> <div class="wmd-panel">
<form method="POST"> <form method="POST">
Tag: <br><input type="text" name="tag"/><br><br> Tag: <br><input type="text" name="tag"/><br><br>
@ -77,4 +73,5 @@ include '../includes/session.php';
</div> </div>
</div> </div>
</body> </body>
</html> </html>
<?php } else {header('location: ../index.php');} ?>

View file

@ -3,14 +3,25 @@
date_default_timezone_set('Asia/Jakarta'); date_default_timezone_set('Asia/Jakarta');
require '../../system/includes/dispatch.php'; require '../../system/includes/dispatch.php';
config('source', '../../admin/config.ini'); config('source', '../../admin/config.ini');
include '../includes/session.php';; include '../includes/session.php';
if(isset($_GET['url'])) { if(isset($_GET['url'])) {
$url = $_GET['url']; $url = $_GET['url'];
} }
else { else {
header('location: ../index.php'); header('location: ../index.php');
} }
?>
if(isset($_POST['submit'])) {
$post_content = $_POST['content'];
}
if(!empty($post_content)) {
file_put_contents('../'. $url, print_r($post_content, true));
header('location: ../index.php');
}
if (login()) {
?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -24,49 +35,38 @@
<body> <body>
<div class="wrapper-outer"> <div class="wrapper-outer">
<div class="wrapper-inner"> <div class="wrapper-inner">
<?php if (login()) { ?>
<div class="nav"> <div class="nav">
<a href="<?php echo config('site.url');?>/admin">Admin</a> <a href="<?php echo config('site.url');?>" target="_blank">Home</a> |
<a href="../includes/create_post.php">Create post</a> <a href="<?php echo config('site.url');?>/admin">Admin</a> |
<a href="../includes/logout.php">Logout</a> <a href="../includes/create_post.php">Create post</a> |
<a href="../includes/logout.php">Logout</a> |
<span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span> <span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span>
</div> </div>
<?php } else {?> <div class="wmd-panel">
<?php header('location: ../index.php');?>
<?php } ?>
<?php
if(isset($_POST['submit'])) {
$post_content = $_POST['content'];
}
if(!empty($post_content)) {
file_put_contents('../'. $url, print_r($post_content, true));
header('location: ../index.php');
}
?>
<div class="wmd-panel">
<form method="POST"> <form method="POST">
<div id="wmd-button-bar" class="wmd-button-bar"></div> <div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="wmd-input" name="content" cols="20" rows="10"><?php echo file_get_contents('../' . $url)?></textarea><br> <textarea id="wmd-input" class="wmd-input" name="content" cols="20" rows="10"><?php echo file_get_contents('../' . $url)?></textarea><br>
<input type="submit" name="submit" value="Submit"/> <input type="submit" name="submit" value="Submit"/>
</form> </form>
</div> </div>
<div id="wmd-preview" class="wmd-panel wmd-preview"></div> <div id="wmd-preview" class="wmd-panel wmd-preview"></div>
<script type="text/javascript"> <script type="text/javascript">
(function () { (function () {
var converter = Markdown.getSanitizingConverter(); var converter = Markdown.getSanitizingConverter();
converter.hooks.chain("preBlockGamut", function (text, rbg) { converter.hooks.chain("preBlockGamut", function (text, rbg) {
return text.replace(/^ {0,3}""" *\n((?:.*?\n)+?) {0,3}""" *$/gm, function (whole, inner) { return text.replace(/^ {0,3}""" *\n((?:.*?\n)+?) {0,3}""" *$/gm, function (whole, inner) {
return "<blockquote>" + rbg(inner) + "</blockquote>\n"; return "<blockquote>" + rbg(inner) + "</blockquote>\n";
});
}); });
});
var editor = new Markdown.Editor(converter);
var editor = new Markdown.Editor(converter);
editor.run();
editor.run(); })();
})(); </script>
</script>
</div> </div>
</div> </div>
</body> </body>
</html> </html>
<?php } else {header('location: ../index.php');} ?>

View file

@ -1,32 +1,74 @@
<?php <?php
include '../includes/session.php';
if(isset($_POST['submit'])) {
if(!empty($_REQUEST['user']) && !empty($_REQUEST['password'])) {
$user = $_POST['user'];
$user_file = 'users/' . $user . '.txt'; $user = $_REQUEST['user'];
$pass = $_POST['password']; $pass = $_REQUEST['password'];
$user_file = '../../admin/users/' . $user . '.txt';
$user_pass = @file_get_contents($user_file); $user_pass = @file_get_contents($user_file);
if(file_exists($user_file)) { if(file_exists($user_file)) {
if($pass === $user_pass) { if($pass === $user_pass) {
$_SESSION['user'] = $user; $_SESSION['user'] = $user;
header('location: index.php'); header('location: ../index.php');
} }
else { else {
echo 'Username and password not match!'; echo <<<EOF
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>
<link rel="stylesheet" type="text/css" href="../resources/style.css" />
</head>
<body>
<div class="wrapper-outer">
<div class="wrapper-inner">
<p>Password and username not match!</p>
<p>Login Form</p>
<form method="POST" action="login.php">
User:<br>
<input type="text" name="user"/><br><br>
Pass:<br>
<input type="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>
</div>
</div>
</body>
</html>
EOF;
} }
} }
else { else {
echo 'Please create username.txt inside "admin/users" folder and put your password inside it.'; echo <<<EOF
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>
<link rel="stylesheet" type="text/css" href="../resources/style.css" />
</head>
<body>
<div class="wrapper-outer">
<div class="wrapper-inner">
<p>Please create username.txt inside "admin/users" folder and put your password inside it.</p>
<p>Login Form</p>
<form method="POST" action="login.php">
User:<br>
<input type="text" name="user"/><br><br>
Pass:<br>
<input type="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>
</div>
</div>
</body>
</html>
EOF;
} }
}
} else {
?> header('location: ../index.php');
<p>Login Form</p> }
<form method="POST"> ?>
User:<br>
<input type="text" name="user"/><br><br>
Pass:<br>
<input type="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>

View file

@ -112,23 +112,20 @@ function get_profile($profile, $page, $perpage){
} }
?> if (isset($_SESSION['user'])) {
<table> $posts = get_profile($_SESSION['user'], null, null);
<?php
$posts = get_profile($_SESSION['user'], null, null); if(!empty($posts)) {
if(!empty($posts)) { echo '<table>';
foreach($posts as $p) {
echo '<tr>';
echo '<td>' . $p->file . '</td>';
echo '<td><form method="GET" action="includes/edit_post.php"><input type="submit" name="submit" value="Edit"/><input type="hidden" name="url" value="' . $p->file . '"/></form></td>';
echo '</tr>';
}
echo '</table>';
foreach($posts as $p) {
echo '<tr>';
echo '<td>' . $p->file . '</td>';
echo '<td><form method="GET" action="includes/edit_post.php"><input type="submit" name="submit" value="Edit"/><input type="hidden" name="url" value="' . $p->file . '"/></form></td>';
echo '</tr>';
} }
}
}
?>
</table>

View file

@ -11,6 +11,4 @@ function login() {
return false; return false;
} }
} }
?>

View file

@ -1,9 +1,8 @@
<?php <?php
ob_start(); date_default_timezone_set('Asia/Jakarta');
date_default_timezone_set('Asia/Jakarta'); require '../system/includes/dispatch.php';
require '../system/includes/dispatch.php'; config('source', '../admin/config.ini');
config('source', '../admin/config.ini'); include 'includes/session.php';
include 'includes/session.php';
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -13,9 +12,31 @@ include 'includes/session.php';
</head> </head>
<body> <body>
<div class="wrapper-outer"> <div class="wrapper-outer">
<div class="wrapper-inner"> <div class="wrapper-inner">
<?php include 'includes/auth.php'; ?> <?php if (login()) { ?>
</div>
<div class="nav">
<a href="<?php echo config('site.url');?>" target="_blank">Home</a> |
<a href="<?php echo config('site.url');?>/admin">Admin</a> |
<a href="includes/create_post.php">Create post</a> |
<a href="includes/logout.php">Logout</a> |
<span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span>
</div>
<?php include 'includes/post_list.php';?>
<?php } else {?>
<p>Login Form</p>
<form method="POST" action="includes/login.php">
User:<br>
<input type="text" name="user"/><br><br>
Pass:<br>
<input type="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>
<?php } ?>
</div>
</div> </div>
</body> </body>
</html> </html>