CodersAdvocate

I work hard, so you don't have to

Creating a PHP CMS for administration

 

Before you begin anything the trick to a very functional CMS is design. So what you need to do first is design the database and table structures. (relational of course).

The first thing you will need to enable is a user log on. So a table holding User IDs, and Passwords. The simpilest form of this table is...
tblUsers(UserID, Login, Password)

Good now you have created this insert an admin user into the table, you can use whatever you like, but i suggest for now use admin as the Login, and for the password.
This is a common DEV thing to do, and leads to the good old saying... "log in using admin, admin".

I'm personally of the school of thinking that the design of the admin pages don't matter, you can use frames tables, or whatever does the job.

The next thing to do is create the log in page, so you will need a form for the user to log in to the CMS suite.
This is a simple form that will do the job (remember i said design aint important, if you want to pretty it up you can do that yourself):

< form method="POST" action="index.php" >
USERNAME< br/ >
< input type="text" name="user" / >

PASSWORD< br/ > < input type="password" name="pass" / > < input type="submit" value="Login" / > < /form >

In this example i have the password and the username submitting in the above form to the server in two input boxes.

Whats next?... Ahh yes, validating user entry.
To validate basic user entry (that is a non encrypted password) you can simple do a select comparing the user name and password to what is stored in the database. If one row is returned you have a valid user.

Given our table structure the select would look something like this...

Select * from tblUsers Where Login = "" and Password = ""

Now lets write that in proper PHP...

< ?php
if (IsSet($_POST['user']){
    if (IsSet($_POST['pass']){
        $strSQL = "SELECT * FROM tblUsers WHERE Login = ";
        $strSQL .= $_POST['user'];
        $strSQL .= " AND Password = ";
        $strSQL .= $_POST['pass'];
        //Here I assume you already have an open DB connection
        $result = mysql_query($strSQL);
        $num = mysql_numrows($result);
    	if ($num > 0){
    	    $_SESSION['user'] = $_POST['user'];
            header("location:blog_options.php");
    	}else{
    	    //Invalid entry do what you like here.
            //personally i don't care
    	}
    }
}
? >

The next thing to do is make the blog_options page, which will be covered at a later date. but for now you have a login mechanisim.
Thanks for reading folks, comment below if you don't understand certain things.

Copyright 2011 CodersAdvocate ©