1
0
Fork 0
chickadee/new-post.php

29 lines
844 B
PHP

<?php
// Bounce if not logged in
$logged_in = $_COOKIE["checkin"] ?? null;
if ( !$logged_in || $logged_in != "waiting for expiry" ) {
header("Location: blog_log.php");
die();
}
$ts = time();
$title = isset( $_POST["post_title"] ) ? trim( $_POST["post_title"] ) : null;
$body = isset( $_POST["post_body"] ) ? trim( $_POST["post_body"] ) : null;
// Bounce if requirements are not met for the post
if ( !$title || !$body || $title == "" || $body == "" ) {
header("Location: blog_log.php?success=0");
die();
}
// Try to write the file
$success = file_put_contents( "./posts/" . $ts . "_" . urlencode( $title ) . ".md", $body );
if ( $success ) {
// Yay! Redirect to admin
header("Location: admin.php?success=1");
die();
} else {
header("Location: admin.php?success=0");
die();
}