Ron Fredericks writes: I am LectureMaker’s video platform technologist. So I thought I would demonstrate some of my sample code in building a simple website demo.
The demo consists of three pages that feature the following code
- PHP programming with OO and model-view-controller (MVC) architecture
- SQL file to create a new table and load some sample user data
- PHP sessions and OO MySQL Data Manager
- Use of CSS style sheet and tags for web page layout and forms management
- Use of JavaScript and jQuery functions and project library
- A RESTful API allowing users to move data between the three pages
Visit the running project’s website here:
www.lecturemaker.com/test/HP_login.php
Download a copy of the project’s source code from GitHub:
https://github.com/RonFredericks/PHP_Demo_Project
Overview
Build a 2-3 page website with a single page view concept with JavaScript mvc and REST service. The concept of the site is to choose your background. After login the user can select a file to upload and that becomes the background image of the landing page. Page 1 is login with at least 3 different users who can login. Page 2 is landing page which will show the image uploaded and page 3 is upload the background image you like. Page 2 and 3 should have a logout button.
FAQ
What is OOP?
Object Oriented Programming, or OOP, invokes the use of classes to organize the data and structure of an application:
- Objects: instances of a class
- Inheritance: ability to pass characteristics and behaviors from a base class
- Access Modifiers: ability to protect data and methods
- Interfaces: a form of abstract class that acts as a model for creating a derived class
- PHP 5 Built-in Classes: Standard PHP Library (SPL), mysqli, PDO, SQLite, XML support, relfection, Iterator interface, magic methods, objects passed by reference
- Design Patterns: a reusable set of solutions that solve practical problems
What is MVC?
Model–View–Controller (MVC) is an architectural pattern used in software engineering:
- Model handles database logic. Code in the model connects to the database and provides an abstraction layer.
- Controller represents the business (application) logic i.e. all our ifs and else.
- View provides the presentation logic i.e our HTML/XML/JSON code.
What is REST?
Representational state transfer (REST) is a predominant web API design model for distributed systems. PHP examples include:
- Use FORM tag with GET or POST to send data to another web page.
- Use cURL to set the URL, create array of POST data, set options such as return XML data, and make request.
- Create a POST request by opening a TCP connection to the host using fsockopen(), then use fwrite() on the handler returned from fsockopen().
Design Methodology
See the figure above “Overview of the Project” where each web page is shown, along with the MySQL database supporting privileged access to the main project’s feature: to upload a new background image.
To start the project code I started with a basic development environment:
- WampServer: a Windows, Apache, MySQL, and PHP development environment. I chose this platform to run my test code because I can development the code directly within the Apache Localhost service without the delay of a repeated ftp style upload.
- Adobe’s DreamWeaver code editor: I use this code editing tool to highlight, format, and check my CSS, HTML, PHP, and JavaScript code. Because I save my files directly into the WampServer, the workflow is fairly efficient.
With this flexible coding environment I create three documents initially: the PHP login page, the CSS file, and a sql field definitions file using a tool called phpmyadmin hosted on my WampServer. I work back and forth between the login page, the CSS file, and the SQL definitions to get the look and feel I have visualized within my wireframe design. I add user fields into my SQL table to manage login storage. And as I start to see a pattern to the JavaScript and PHP support needs for this project: I prepare to add PHP classes, PHP support functions, and JavaScript code into new files as the code is development.
Create Login Page, CSS Stylesheet and SQL file
Create Landing Page
Create Image Upload Page
Create PHP Initialize File
Create Database Class
Create User Class
Create User Manager Class
-
-
////////////////////////////////// Create Login Page ///////////////////////
-
-
< ?php
-
// File: HP_login.php
-
// Purpose: Initialize and start PHP session
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/10/2013
-
-
require_once ‘./HP_assets/HP_initialize.php’;
-
?>
-
< !doctype html>
-
"utf-8"/>
-
Login Page -
"stylesheet" type="text/css" href="./HP_assets/HP_main.css"/>
-
< ?php
-
// Insure that prior users are logged out of this web service
-
$um->logout();
-
// Initiate page div layout and display heading
-
PutHeader(HEADING);
-
// Initiate login
-
LoginForm("HP_uploadImage.php");
-
SelectValidUser();
-
// Complete page div layout and display footer
-
PutFooter(FOOTER);
-
?>
-
-
////////////////////////////////// Create Landing Page ///////////////////////
-
-
< ?php
-
// File: HP_landingPage.php
-
// Purpose: Initialize and start PHP session
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/10/2013
-
-
require_once ‘./HP_assets/HP_initialize.php’;
-
?>
-
< !doctype html>
-
"utf-8"/>
-
Landing Page -
"stylesheet" type="text/css" href="./HP_assets/HP_main.css"/>
-
body
-
{
-
background-image:url(‘./HP_assets/HP_paper.gif’);
-
}
-
< ?php
-
-
PutHeader(HEADING);
-
-
Redirect(‘HP_login.php’, 5);
-
}
-
?>
-
newText = "< ?php echo ‘Welcome: ‘ . $user->get(‘username’); ?>";
-
update_id_text("header_lft", newText);
-
-
< ?php
-
PutErrorMessage(ProcessUploadForm());
-
PutFooter(FOOTER);
-
?>
-
-
////////////////////////////////// Create Image Upload Page ///////////////////////
-
-
< ?php
-
// File: HP_uploadImage.php
-
// Purpose: Initialize and start PHP session
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/10/2013
-
-
require_once ‘./HP_assets/HP_initialize.php’;
-
?>
-
< !doctype html>
-
"utf-8"/>
-
Upload Image -
"stylesheet" type="text/css" href="./HP_assets/HP_main.css"/>
-
< ?php
-
// Attempt to process user login form $_POST
-
if (ProcessLoginForm($um)) {
-
// update user info on successful new login
-
$user = $um->getSession();
-
}
-
PutHeader(HEADING);
-
// Test for valid user, return to login page if user not valid
-
Redirect(‘HP_login.php’, 5);
-
}
-
?>
-
-
-
// Insert user name into heading
-
newText = "< ?php echo ‘Welcome: ‘ . $user->get(‘username’); ?>";
-
update_id_text("header_lft", newText);
-
-
-
< ?php
-
// Initiate image upload form
-
GetImageForm("HP_landingPage.php");
-
DisplayValidImageTypes();
-
PutFooter(FOOTER);
-
?>
-
-
////////////////////////////////// Create PHP Initialize File ///////////////////////
-
-
< ?php
-
// File: HP_initialize.php
-
// Initialize PHP environment
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/10/2013
-
-
error_reporting(-1); // set to (-1) to display all errors, (0) for no errors and (E_ALL ^ E_NOTICE) for default production
-
$validext = array(".gif"=>"GIF image", ".jpeg"=>"JPEG image", ".jpg"=>"JPG image", ".png"=>"PNG image");
-
// include the mySQL data management system
-
require_once ‘./HP_assets/HP_UserManager.php’;
-
require_once ‘./HP_assets/HP_miscFunctions.php’;
-
//
-
//session_start();
-
$um = new UserManager();
-
$user = $um->getSession();
-
-
////////////////////////////////// Create Database Class ///////////////////////
-
-
< ?php
-
// File: HP_Database.php
-
// Purpose: Define a class to MySQL database connection class
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/10/2013
-
// References:
-
// http://forum.zonehacks.com/threads/10-PHP-User-Management-System-using-Object-Oriented-Programming-and-MySQL
-
// Object-Oriented PHP by Peter Lavin, No Starch Press, 2006
-
class Database {
-
-
/**
-
* =============================================================
-
* Change these values to work with your mysql database settings
-
* =============================================================
-
*/
-
private $db_host = ‘localhost’;
-
private $db_user = ‘xxx’; // fill in these values with your credentials
-
private $db_pass = ‘xxx’;
-
private $db_name = ‘xxx’; // fill in your mySQL atabase name here
-
-
-
private $link;
-
-
// see __call method below for implementaiton, RDF
-
‘affected_rows’ => ‘mysql_affected_rows’,
-
‘client_encoding’ => ‘mysql_client_encoding’,
-
‘close’ => ‘mysql_close’,
-
‘connect’ => ‘mysql_connect’,
-
‘create_db’ => ‘mysql_create_db’,
-
‘data_seek’ => ‘mysql_data_seek’,
-
‘db_name’ => ‘mysql_db_name’,
-
‘db_query’ => ‘mysql_db_query’,
-
‘drop_db’ => ‘mysql_drop_db’,
-
‘errno’ => ‘mysql_errno’,
-
‘error’ => ‘mysql_error’,
-
‘escape_string’ => ‘mysql_escape_string’,
-
‘fetch_array’ => ‘mysql_fetch_array’,
-
‘fetch_assoc’ => ‘mysql_fetch_assoc’,
-
‘fetch_field’ => ‘mysql_fetch_field’,
-
‘fetch_lengths’ => ‘mysql_fetch_lengths’,
-
‘fetch_object’ => ‘mysql_fetch_object’,
-
‘fetch_row’ => ‘mysql_fetch_row’,
-
‘field_flags’ => ‘mysql_field_flags’,
-
‘field_len’ => ‘mysql_field_len’,
-
‘field_name’ => ‘mysql_field_name’,
-
‘field_seek’ => ‘mysql_field_seek’,
-
‘field_table’ => ‘mysql_field_table’,
-
‘field_type’ => ‘mysql_field_type’,
-
‘free_result’ => ‘mysql_free_result’,
-
‘get_client_info’ => ‘mysql_get_client_info’,
-
‘get_host_info’ => ‘mysql_get_host_info’,
-
‘get_proto_info’ => ‘mysql_get_proto_info’,
-
‘get_server_info’ => ‘mysql_get_server_info’,
-
‘info’ => ‘mysql_info’,
-
‘insert_id’ => ‘mysql_insert_id’,
-
‘list_dbs’ => ‘mysql_list_dbs’,
-
‘list_fields’ => ‘mysql_list_fields’,
-
‘list_processes’ => ‘mysql_list_processes’,
-
‘list_tables’ => ‘mysql_list_tables’,
-
‘num_fields’ => ‘mysql_num_fields’,
-
‘num_rows’ => ‘mysql_num_rows’,
-
‘pconnect’ => ‘mysql_pconnect’,
-
‘ping’ => ‘mysql_ping’,
-
‘query’ => ‘mysql_query’,
-
‘real_escape_string’ => ‘mysql_real_escape_string’,
-
‘result’ => ‘mysql_result’,
-
‘select_db’ => ‘mysql_select_db’,
-
‘set_charset’ => ‘mysql_set_charset’,
-
‘stat’ => ‘mysql_stat’,
-
‘tablename’ => ‘mysql_tablename’,
-
‘thread_id’ => ‘mysql_thread_id’,
-
‘unbuffered_query’ => ‘mysql_unbuffered_query’
-
);
-
-
function __construct()
-
{
-
if (Database::$instances == 0) {
-
$this->link = @$this->connect($this->db_host, $this->db_user, $this->db_pass); // catch and hide error messages using "@", RDF
-
if(!$this->link) {
-
die("Database class: ".mysql_error(). " Error no: ".mysql_errno()); // Include all possible error messages in display, RDF
-
}
-
-
$this->select_db($this->db_name);
-
Database::$instances = 1;
-
}
-
}
-
-
function __destruct()
-
{
-
if($this->link) {
-
Database::$instances == 0;
-
}
-
}
-
-
// Manage undeclared functions
-
public function __call($name, $arguments) {
-
}
-
return FALSE;
-
}
-
-
}
-
-
////////////////////////////////// Create User Class ///////////////////////
-
-
< ?php
-
// File: HP_User.php
-
// Purpose: User class to manage undefined data members
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/10/2013
-
// References:
-
// http://forum.zonehacks.com/threads/10-PHP-User-Management-System-using-Object-Oriented-Programming-and-MySQL
-
// Object-Oriented PHP by Peter Lavin, No Starch Press, 2006
-
class User
-
{
-
-
-
public function checkPassword($pass)
-
{
-
return true;
-
}
-
return false;
-
}
-
-
public function set($var, $value)
-
{
-
$this->userdata[$var] = $value;
-
}
-
-
public function get($var)
-
{
-
return $this->userdata[$var];
-
}
-
return NULL;
-
}
-
}
-
-
////////////////////////////////// Create User Manager Class ///////////////////////
-
-
< ?php
-
// File: HP_UserManager.php
-
// Purpose: Create a class to manage user functions using a MySQL database
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/10/2013
-
// References:
-
// http://forum.zonehacks.com/threads/10-PHP-User-Management-System-using-Object-Oriented-Programming-and-MySQL
-
// Object-Oriented PHP by Peter Lavin, No Starch Press, 2006
-
-
// Include the User and Database class files
-
require_once "./HP_assets/HP_User.php";
-
require_once "./HP_assets/HP_Database.php";
-
-
class UserManager
-
{
-
private $db;
-
-
// Create an instance of the database class and store it into a private variable
-
public function UserManager()
-
{
-
$this->db = new Database();
-
}
-
-
public function createUser($username, $password, $email, $is_admin = FALSE)
-
{
-
$stmt = sprintf("INSERT INTO users (`id`, `username`, `password`, `email`, `is_admin`) VALUES (NULL, ‘%s’, ‘%s’, ‘%s’, ‘%d’)",
-
$this->db->real_escape_string($username),
-
md5($this->db->real_escape_string($password)), // A md5 hash of the user’s password will be stored in the database.
-
$this->db->real_escape_string($email), // always escape data from public before storing in database
-
$this->db->real_escape_string($is_admin));
-
$result = $this->db->query($stmt);
-
-
if ($result) return true;
-
}
-
return false;
-
}
-
-
public function updateUser($user)
-
{
-
// Normally I wouldn’t store session data in the database, but
-
// it can be changed to track cookies if you plan to go that
-
// route.
-
$session = $user->get(‘session’);
-
if (!$session) $session = 0;
-
$stmt = sprintf("UPDATE users SET `username` = ‘%s’, `password` = ‘%s’, `email` = ‘%s’, `is_admin` = ‘%d’, `session` = ‘%s’ WHERE `id` = ‘%d’",
-
$this->db->real_escape_string($user->get(‘username’)),
-
$this->db->real_escape_string($user->get(‘password’)),
-
$this->db->real_escape_string($user->get(’email’)),
-
$this->db->real_escape_string($user->get(‘is_admin’)),
-
$this->db->real_escape_string($session),
-
$this->db->real_escape_string($user->get(‘id’)));
-
return $this->db->query($stmt);
-
}
-
-
public function deleteUser($user)
-
{
-
$userID = $this->db->real_escape_string($user->get(‘id’));
-
return $this->db->query("DELETE FROM users WHERE `id` = ‘$userID’");
-
}
-
-
// Get users from the database and return a user object by id or username
-
public function getUserByID($id)
-
{
-
-
// get the user by id from database
-
$result = $this->db->query($stmt);
-
if($result) {
-
$user = new User(); // create a new user object
-
$row = $this->db->fetch_assoc($result);
-
foreach($row as $key => $value) { // loop through user table values
-
$user->set($key, $value); // store them in the user object
-
}
-
return $user; // and return it
-
}
-
}
-
return NULL;
-
}
-
-
public function getUserByName($name)
-
{
-
-
if ($result && $this->db->num_rows($result) > 0) {
-
$user = new User();
-
$row = $this->db->fetch_assoc($result);
-
foreach($row as $key => $value) {
-
$user->set($key, $value);
-
}
-
return $user;
-
}
-
}
-
return NULL;
-
}
-
-
// Get user by name, check the password, updates session info in the database, and return the user object
-
public function login($username, $password)
-
{
-
$user = $this->getUserByName($username);
-
// start PHP session, RDF
-
$_SESSION[‘zhuser’] = $user->get(‘username’); // I normally use these for cookies
-
$user->set(‘session’, $_SESSION[‘zhsess’]); // set the session in user object
-
$this->updateUser($user); // update the user
-
return $user; // and return the user object if we’re good
-
}
-
}
-
return NULL;
-
}
-
-
public function logout()
-
{
-
}
-
}
-
-
// Check if a session exists and against what we have stored in the database, if they match we’re good
-
public function getSession()
-
{
-
// start PHP session, RDF
-
-
$user = $this->getUserByName($_SESSION[‘zhuser’]);
-
if (!$user) $this->logout();
-
if ($user->get(‘session’) == $_SESSION[‘zhsess’]) {
-
return $user;
-
}
-
}
-
return NULL;
-
}
-
}
-
Create PHP Functions Page
-
< ?php
-
// File: HP_miscFunctions.php
-
// Purpose: PHP Visual display and support functions
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/11/2013
-
-
-
//////////////////////////////////////////////////////////////////
-
// Login Support Functions //
-
//////////////////////////////////////////////////////////////////
-
-
function LoginForm($url)
-
// Present a login form
-
{
-
// Reference: http://designikx.wordpress.com/2010/04/07/pure-css-div-based-form-design-form-layout/
-
?>
-
-
-
"myform">
Login Window
Welcome to the background image selector website
Its Your Name"username" type="text" name="username"/>Enter Your Password"password" type="text" name="password"/> -
< ?php
-
}
-
-
function SelectValidUser()
-
// Present list of valid users for login
-
{
-
?>
-
"myformsupport">
Login List
Load one of these valid user credentials into login window
- Ron Fredericks
- Tommy Tuba
- Admin
-
< ?php
-
}
-
-
function ProcessLoginForm($um)
-
{
-
{
-
// Attempt to login
-
$user = $um->login($_REQUEST[‘username’], $_REQUEST[‘password’]);
-
// Login failed, try again
-
if(!$user)
-
{
-
PutHeader(HEADING);
-
PutErrorMessage ("Invalid login, try selecting a user from the list…");
-
Redirect("HP_login.php", 5);
-
PutFooter(FOOTER);
-
} else {
-
// login was succesful
-
return true;
-
}
-
}
-
// login was either not successful or no login info was requested
-
return false;
-
}
-
-
-
//////////////////////////////////////////////////////////////////
-
// Upload Image Support Functions //
-
//////////////////////////////////////////////////////////////////
-
-
function GetImageForm($url)
-
// Present a login form
-
{
-
// Reference: http://designikx.wordpress.com/2010/04/07/pure-css-div-based-form-design-form-layout/
-
?>
-
-
"mygetimageform">
Load New Background Image Window
Welcome to the background image selector website
"file" name="file" id="file" size="40"/> -
< ?php
-
}
-
-
function DisplayValidImageTypes()
-
// Present list of valid file types for image upload
-
{
-
global $validext;
-
-
echo ‘’;echo ‘
Valid File Types
’;echo ‘Choose a file to load with one of these valid extensions:
’;echo ‘- ’
foreach ($validext as $key => $value) {echo "- $value [$key]
";}echo ‘’;echo ”;}function UploadFile($origin, $dest, $tmp_name)// reference: function GetImageForm($url){global $validext;$fulldest = $dest.$origin;$filename = $origin;$validflag = false;foreach($validext as $ext=>$type) {if ($fileext === $ext) {$validflag = true;break;}}if (!$validflag) {PutErrorMessage("Error: invalid file extension [$fileext]");return false;}$fulldest = $dest.$filename;}return false;}function DeleteImageFiles($directory, $days)// delete files from a diectory,// return number of files deleted,// $directory must be: 1) a relative address and 2) not the same directory as the php file, for safety{$count = 0;$seconds = $days * 24 * 60 * 60;foreach($files as $file) {$count++;}}}return $count;}function ProcessUploadForm()// reference: function GetImageForm($url){$msg= "";PutErrorMessage("You did not select an image for landing page, please try again…");Redirect(‘HP_uploadImage.php’, 5);}// process file name requested on client’s computer as a result of client’s use of the ‘browse’ buttonif ($_FILES["file"]["error"] > 0) {$msg .= "Error: " . $_FILES["file"]["error"] . "";}else {// file found$fileCnt = DeleteImageFiles(IMAGE_DIR, 0); // remove old imagesif (DEBUG) {$msg .= "$fileCnt prior images removed from " . IMAGE_DIR . " image directory";$msg .= "Upload: " . $_FILES["file"]["name"] . "";$msg .= "Type: " . $_FILES["file"]["type"] . "";$msg .= "temp: " . $_FILES["file"]["tmp_name"] . "";";}$result = UploadFile($_FILES["file"]["name"], IMAGE_DIR, $_FILES["file"]["tmp_name"]);if ($result) {if (DEBUG) {$msg .= "Result: " . IMAGE_DIR . $result."";}?>imgLink = "< ?php echo IMAGE_DIR . $result ; ?>";update_background_image(imgLink);< ?php}else {$msg .= "Upload was not successful";}}}return $msg;}//////////////////////////////////////////////////////////////////// Page Display Functions ////////////////////////////////////////////////////////////////////function PutHeader($heading, $left="", $right="")// Initialize web page structure and display heading{?>< ?php}function PutErrorMessage($msg)// Manage display format for error messages{echo "$msg"
;}}function Redirect($url, $waitSeconds = 0)// Redirect to another web page{//header("Location: $url"); // Rewrite the headerecho "";?>count_down(‘#timeMsg’, ‘span’);< ?phpPutFooter(FOOTER);}function GetButtons()// Dislplay user options as buttons when logged in{$msg="";$msg .= "javascript:open_window(‘HP_login.php’, ‘_self’);\">Log Out";$msg .= "open_window(‘HP_landingPage.php’, ‘_self’);\">Landing Page";$msg .= "open_window(‘HP_uploadImage.php’, ‘_self’);\">New Image";}//var_dump($_SESSION);return $msg;}function GetCurrentPage()// Return current web page{}?>Create JavaScript Functions Page
Code (javascript)-
// JavaScript Document
-
// HP_functions.js
-
// Author: Ron Fredericks, LectureMaker LLC
-
// Last Updated: 7/10/2013
-
-
function count_down(msgTag, msgSpan)
-
{
-
// display the count down of seconds within the text when time is greater than 0
-
var sec = $(msgTag+" "+msgSpan).text() || 0;
-
var timer = setInterval(function() {
-
$(msgTag+" "+msgSpan).text(–sec);
-
if (sec < = 0) {
-
$(msgTag).fadeOut(‘fast’);
-
clearInterval(timer);
-
}
-
}, 1000);
-
}
-
-
function load_login(user)
-
// stuff Login Form with valid user credentials
-
{
-
if (user == "Ron Fredericks") {
-
$(‘#username’).focus(function() {
-
this.value="Ron Fredericks";
-
});
-
$(‘#username’).focus();
-
$(‘#password’).focus(function() {
-
this.value="rf";
-
});
-
$(‘#password’).focus();
-
}
-
else if (user == "Tommy Tuba") {
-
$(‘#username’).focus(function() {
-
this.value="Tommy Tuba";
-
});
-
$(‘#username’).focus();
-
$(‘#password’).focus(function() {
-
this.value="tt";
-
});
-
$(‘#password’).focus();
-
}
-
else if (user == "Admin") {
-
$(‘#username’).focus(function() {
-
this.value="Admin";
-
});
-
$(‘#username’).focus();
-
$(‘#password’).focus(function() {
-
this.value="aStrongPassword";
-
});
-
$(‘#password’).focus();
-
}
-
}
-
-
function login_form(form)
-
{
-
var x=form.username;
-
if (!x.value) {
-
alert("Username must be filled out");
-
x.focus();
-
return false;
-
}
-
var y=form.password;
-
if (!y.value) {
-
alert("Password must be filled out");
-
y.focus();
-
return false;
-
}
-
return true;
-
}
-
-
function open_window(url, target)
-
// Open a browser window
-
// url is web address
-
// target specified the attribute or name of the window
-
// _blank – URL is loaded into a new window. This is default
-
// _parent – URL is loaded into the parent frame
-
// _self – URL replaces the current page
-
// _top – URL replaces any framesets that may be loaded
-
// name – The name of the window
-
{
-
window.open(url, target);
-
}
-
-
function update_background_image(imgLink)
-
// update css body background image
-
{
-
$("body").css("background", "url(‘" + imgLink + "’)");
-
}
-
-
function update_id_text(id, text)
-
// update css id text
-
{
-
//$(div).css(id, text);
-
$("#"+id).text(text);
-
}
-
Create CSS Style Sheet
Code (css)-
@charset "utf-8";
-
/* CSS Document */
-
/* File: HP_main.css */
-
/* Author: Ron Fredericks, LectureMaker LLC */
-
/* Last Updated: 7/10/2013 */
-
-
p{font-size:14px;margin:0;padding:0;}
-
h1{font-size:18px;margin:0;padding:0;}
-
-
#myform
-
{
-
width:400px;
-
border:2px solid grey;
-
padding:14px;
-
margin:0 auto;
-
}
-
-
#mygetimageform
-
{
-
width:400px;
-
border:2px solid grey;
-
padding:14px;
-
margin:0 auto;
-
}
-
-
#myformsupport
-
{
-
width:400px;
-
padding:14px;
-
margin:0 auto;
-
}
-
-
.mystyle
-
{
-
border-bottom:1px solid grey;
-
padding:5px 0 5px 0;
-
margin:0 0 10px 0;
-
}
-
-
.myerror
-
{
-
font-size:16px;
-
width:350px;
-
padding:5px 5px 5px 5px;
-
color:red;
-
background-color:white;
-
}
-
-
#timeMsg
-
{
-
font-size:16px;
-
width:350px;
-
padding:5px 5px 5px 5px;
-
background-color:white;
-
}
-
-
#myform label
-
{
-
font-size:13px;
-
float:left;
-
width:200px;
-
text-align:right;
-
display:block;
-
}
-
-
#myform span
-
{
-
font-size:11px;
-
color:grey;
-
width:200px;
-
text-align:right;
-
display:block;
-
}
-
-
#myform input
-
{
-
border:1px solid grey;
-
font-family:verdana;
-
font-size:12px;
-
color:grey;
-
height:16px;
-
width:150px;
-
margin:5px 0 20px 10px;
-
}
-
-
#myform button
-
{
-
clear:both;
-
margin-left:150px;
-
background:grey;
-
color:#FFFFFF;
-
border:solid 1px #666666;
-
font-size:12px;
-
cursor:pointer;
-
}
-
-
#myformsupport button
-
{
-
clear:both;
-
margin-left:5px;
-
margin-right:5px;
-
background:grey;
-
color:#FFFFFF;
-
border:solid 1px #666666;
-
font-size:12px;
-
cursor:pointer;
-
}
-
-
#myformsupport ul
-
{
-
margin-left:-25px;
-
list-style-image:url("HP_arrow.gif")
-
}
-
-
html,
-
body {
-
margin:0;
-
padding:0;
-
height:100%;
-
}
-
-
#container {
-
min-height:100%;
-
position:relative;
-
}
-
-
#header_ctr {
-
color:white;
-
text-align:center;
-
background:#333;
-
padding:10px;
-
-
}
-
-
#header_lft {
-
color:white;
-
float:left;
-
background:#333;
-
}
-
-
#header_rt {
-
color:white;
-
float:right;
-
background:#333;
-
}
-
-
#body {
-
padding:10px;
-
padding-bottom:20px; /* Height of the footer */
-
}
-
-
#footer {
-
color:white;
-
text-align:center;
-
position:absolute;
-
bottom:0;
-
width:100%;
-
height:20px; /* Height of the footer */
-
background:#333;
-
}
-
-
#header a, #header a:visited, #footer a, #footer a:visited {
-
color: #eee;
-
}
Define MySQL Data
Code (sql)-
-
/* Prepare MySQL Table for use in project */
-
/* File: HP_InitializeMySQL.sql */
-
/* Author: Ron Fredericks, LectureMaker LLC */
-
/* Last Update: 7/10/2013 */
-
-
DROP TABLE IF EXISTS `users`;
-
-
CREATE TABLE `users` (
-
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-
`username` varchar(60) NOT NULL,
-
`password` varchar(32) NOT NULL,
-
`email` varchar(60) NOT NULL,
-
`is_admin` int(1) NOT NULL DEFAULT ‘0’,
-
`session` varchar(32) NOT NULL,
-
PRIMARY KEY (`id`),
-
UNIQUE KEY `username` (`username`)
-
) ENGINE=MyISAM;
-
-
INSERT INTO users (`username`, `password`, `email`, `is_admin`) VALUES
-
( "Ron Fredericks", md5("rf"), "your@domain.com", 0 ),
-
( "Tommy Tuba", md5("tt"), "your@domain.com", 0 ),
-
("Admin", md5("aStrongPassword"), "your@domain.com", 1);
Misc. Components
HP_arrow.gif
HP_paper.gif