diff --git a/README.md b/README.md index 438f871..bf15ffb 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ simplog is a (very) simple PHP blog engine. It's supposed to be implemented into What's missing? --------------- -Not much really as of 2013-07-27, depending on how you plan to use it. Included is a template to create the MySQL table, a small HTML and PHP file to create new posts, an index.php file that displays your posts and a config file to connect to a database and set number of posts per page. Now there is also a HTML file to find your posts and edit/update them. Note that you need to protect the user directory yourself (with for example a .htaccess file), or else everyone can post on your blog. +Not much really as of 2013-07-27, depending on how you plan to use it. Included is a template to create the MySQL table, a small HTML and PHP file to create new posts, an index.php file that displays your posts and a config file to connect to a database and set number of posts per page. Now there is also a HTML file to find your posts and edit/update them. + +You no longer need to protect the user/ directory yourself. Authentication is done using the database. Usage ----- @@ -13,11 +15,21 @@ simplog.php is intended to be included (with php include) on your webpage, there How do I create the MySQL table? -------------------------------- -Either create a new database and possibly a new user or use an existing database/user and run the command: + +Either create a new mysql user and database or use an existing one, then either: + +Option 1) Go to http://mydomain.tld/path-to-simplog/install.php + + or... + +Option 2) Run this command from the shell: mysql -u -p < blogtable.sql -You'll be asked to enter the passwor for the user, enter it. Now you have created the table for the blog. Now you can start filling it with blog posts. +You'll be asked to enter the password for the user, enter it. + + +Now you have created the table for the blog. Now you can start filling it with blog posts. Contributing ------------ diff --git a/blogtable.sql b/blogtable.sql index beeeae2..6e8d492 100644 --- a/blogtable.sql +++ b/blogtable.sql @@ -1,7 +1,18 @@ CREATE TABLE `blog` ( - `postnumber` int(11) NOT NULL AUTO_INCREMENT, + `postnumber` int(11) NOT NULL AUTO_INCREMENT, `date` date NOT NULL, `title` text COLLATE utf8_unicode_ci NOT NULL, `posttext` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`postnumber`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(20) NOT NULL, + `name` varchar(40) NOT NULL, + `password` varchar(64) NOT NULL, + `session` int(64), + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +INSERT INTO `users` (`id`, `username`, `name`, `password`, `session`) VALUES (NULL, 'admin', 'Admin', PASSWORD('admin'), NULL); diff --git a/includes/dbconnect.php b/includes/dbconnect.php index 4c4550c..c79d11d 100644 --- a/includes/dbconnect.php +++ b/includes/dbconnect.php @@ -1,4 +1,5 @@ diff --git a/includes/login_form.inc b/includes/login_form.inc new file mode 100644 index 0000000..77103c4 --- /dev/null +++ b/includes/login_form.inc @@ -0,0 +1,16 @@ +
+ + + + + + + + + + + + + + +
Username
Password
diff --git a/install.php b/install.php new file mode 100644 index 0000000..484f4f2 --- /dev/null +++ b/install.php @@ -0,0 +1,48 @@ + + +

Installer

+ +"; +} else { + echo "Table 'Blog' created successfully.
"; +} + +# Try to create 'blog_users' table +$sql = "CREATE TABLE `blog_users` (`id` int(11) NOT NULL AUTO_INCREMENT,`username` varchar(20) NOT NULL,`name` varchar(40) NOT NULL,`password` varchar(64) NOT NULL,`session` int(64), PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; +$result = mysql_query($sql); +if (mysql_error()) { + echo mysql_error() . ".
"; +} else { + echo "Table 'Users' created successfully.
"; +} + +# Try to create 'admin' user +$sql = "INSERT INTO `blog_users` (`id`, `username`, `name`, `password`, `session`) VALUES (NULL, 'admin', 'Admin', PASSWORD('admin'), NULL);"; +$result = mysql_query($sql); +if (mysql_error()) { + echo "User 'admin' already exists.
"; +} else { + echo "User 'admin/admin' created successfully.
"; +} + +end_html(); +?> diff --git a/user/edit.php b/user/edit.php index 5a068e9..7a1a26a 100644 --- a/user/edit.php +++ b/user/edit.php @@ -1,6 +1,7 @@

Find post to edit

diff --git a/user/editpost.php b/user/editpost.php index 9d33e70..45447fd 100644 --- a/user/editpost.php +++ b/user/editpost.php @@ -6,6 +6,8 @@ require "../includes/dbconnect.php"; require "../includes/htmlcode.php"; start_html("Edit post"); +include "../includes/login.inc"; + print "

Edit post

"; $query = "SELECT * FROM blog WHERE date='$_GET[date]' AND title='$_GET[title]'"; diff --git a/user/index.php b/user/index.php index 30b3fa7..14877eb 100644 --- a/user/index.php +++ b/user/index.php @@ -1,6 +1,7 @@

simplog user interface

diff --git a/user/new.php b/user/new.php index ad65beb..54f8c3c 100644 --- a/user/new.php +++ b/user/new.php @@ -1,11 +1,12 @@

Create new post

-Date: (YYYY-MM-DD) +Date: (DD-MM-YYYY)
Title:

diff --git a/user/updatepost.php b/user/updatepost.php index 6c79e1e..e4748aa 100644 --- a/user/updatepost.php +++ b/user/updatepost.php @@ -6,6 +6,7 @@ require "../includes/dbconnect.php"; require "../includes/htmlcode.php"; start_html("Post updated"); +include "../includes/login.inc"; $query = "UPDATE blog SET date='$_POST[date]', title='$_POST[title]',