Just archiving this project from my Open Source Software class.
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$fileName = basename(__FILE__, ".php"); //grabs the file name and drops the extension
|
||||
$fileName = str_replace('-', ' ', $fileName); //replaces all hypens with a space
|
||||
$fileName = ucwords($fileName); //capitalizes the first letter of every word
|
||||
include("templates/header.php");
|
||||
?>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
$fileName = "Your Cart";
|
||||
include("templates/header.php");
|
||||
if(!isset($_SESSION['user_name'])){
|
||||
header('location: home.php');
|
||||
}
|
||||
?>
|
||||
<div id="shopping-cart">
|
||||
<h1>Your Cart</h1>
|
||||
<?php if (count($_SESSION['cart12']) == 0) : ?>
|
||||
<p>There are no items in your cart.</p>
|
||||
<?php else: ?>
|
||||
<form action="shopping-cart-index.php?action=update" method="post">
|
||||
<input type="hidden" name="action" value="update"/>
|
||||
<table>
|
||||
<tr id="cart_header">
|
||||
<th class="left">Item</th>
|
||||
<th class="right">Item Cost</th>
|
||||
<th class="right">Quantity</th>
|
||||
<th class="right">Item Total</th>
|
||||
</tr>
|
||||
|
||||
<?php foreach( $_SESSION['cart12'] as $key => $item ) :
|
||||
$cost = number_format($item['cost'], 2);
|
||||
$total = number_format($item['total'], 2);
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php echo $item['name']; ?>
|
||||
</td>
|
||||
<td class="right">
|
||||
$<?php echo $cost; ?>
|
||||
</td>
|
||||
<td class="right">
|
||||
<input type="text" class="cart_qty"
|
||||
name="newqty[<?php echo $key; ?>]"
|
||||
value="<?php echo $item['qty']; ?>"/>
|
||||
</td>
|
||||
<td class="right">
|
||||
$<?php echo $total; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<tr id="cart_footer">
|
||||
<td colspan="3"><b>Subtotal</b></td>
|
||||
<td>$<?php echo get_subtotal(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4" class="right">
|
||||
<input type="submit" value="Update Cart"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>Click "Update Cart" to update quantities in your
|
||||
cart. Enter a quantity of 0 to remove an item.
|
||||
</p>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<p><a href="shopping-cart-index.php?action=show_add_item">Add Item</a></p>
|
||||
<p><a href="shopping-cart-index.php?action=empty_cart">Empty Cart</a></p>
|
||||
</div><!-- end shopping-cart -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class login
|
||||
*
|
||||
* handles the user login/logout/session
|
||||
* @author Panique
|
||||
* @link http://www.php-login.net
|
||||
* @link https://github.com/panique/php-login/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class Login
|
||||
{
|
||||
/**
|
||||
* @var object The database connection
|
||||
*/
|
||||
private $db_connection = null;
|
||||
/**
|
||||
* @var string The user's name
|
||||
*/
|
||||
private $user_name = "";
|
||||
/**
|
||||
* @var string The user's mail
|
||||
*/
|
||||
private $user_email = "";
|
||||
/**
|
||||
* @var string The user's password hash
|
||||
*/
|
||||
private $user_password_hash = "";
|
||||
/**
|
||||
* @var boolean The user's login status
|
||||
*/
|
||||
private $user_is_logged_in = false;
|
||||
/**
|
||||
* @var array Collection of error messages
|
||||
*/
|
||||
public $errors = array();
|
||||
/**
|
||||
* @var array Collection of success / neutral messages
|
||||
*/
|
||||
public $messages = array();
|
||||
|
||||
/**
|
||||
* the function "__construct()" automatically starts whenever an object of this class is created,
|
||||
* you know, when you do "$login = new Login();"
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
// TODO: adapt the minimum check like in 0-one-file version
|
||||
|
||||
// create/read session
|
||||
session_start();
|
||||
|
||||
// check the possible login actions:
|
||||
// 1. logout (happen when user clicks logout button)
|
||||
// 2. login via session data (happens each time user opens a page on your php project AFTER he has sucessfully logged in via the login form)
|
||||
// 3. login via post data, which means simply logging in via the login form. after the user has submit his login/password successfully, his
|
||||
// logged-in-status is written into his session data on the server. this is the typical behaviour of common login scripts.
|
||||
|
||||
// if user tried to log out
|
||||
if (isset($_GET["logout"])) {
|
||||
$this->doLogout();
|
||||
}
|
||||
// if user has an active session on the server
|
||||
elseif (!empty($_SESSION['user_name']) && ($_SESSION['user_logged_in'] == 1)) {
|
||||
$this->loginWithSessionData();
|
||||
}
|
||||
// if user just submitted a login form
|
||||
elseif (isset($_POST["login"])) {
|
||||
$this->loginWithPostData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* log in with session data
|
||||
*/
|
||||
private function loginWithSessionData()
|
||||
{
|
||||
// set logged in status to true, because we just checked for this:
|
||||
// !empty($_SESSION['user_name']) && ($_SESSION['user_logged_in'] == 1)
|
||||
// when we called this method (in the constructor)
|
||||
$this->user_is_logged_in = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* log in with post data
|
||||
*/
|
||||
private function loginWithPostData()
|
||||
{
|
||||
// if POST data (from login form) contains non-empty user_name and non-empty user_password
|
||||
if (!empty($_POST['user_name']) && !empty($_POST['user_password'])) {
|
||||
|
||||
// create a database connection, using the constants from config/db.php (which we loaded in index.php)
|
||||
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
|
||||
// if no connection errors (= working database connection)
|
||||
if (!$this->db_connection->connect_errno) {
|
||||
|
||||
// escape the POST stuff
|
||||
$this->user_name = $this->db_connection->real_escape_string($_POST['user_name']);
|
||||
// database query, getting all the info of the selected user
|
||||
$checklogin = $this->db_connection->query("SELECT user_name, user_email, user_password_hash FROM users WHERE user_name = '" . $this->user_name . "';");
|
||||
|
||||
// if this user exists
|
||||
if ($checklogin->num_rows == 1) {
|
||||
|
||||
// get result row (as an object)
|
||||
$result_row = $checklogin->fetch_object();
|
||||
|
||||
// using PHP 5.5's password_verify() function to check if the provided passwords fits to the hash of that user's password
|
||||
if (password_verify($_POST['user_password'], $result_row->user_password_hash)) {
|
||||
|
||||
// write user data into PHP SESSION [a file on your server]
|
||||
$_SESSION['user_name'] = $result_row->user_name;
|
||||
$_SESSION['user_email'] = $result_row->user_email;
|
||||
$_SESSION['user_logged_in'] = 1;
|
||||
|
||||
// set the login status to true
|
||||
$this->user_is_logged_in = true;
|
||||
|
||||
} else {
|
||||
$this->errors[] = "Wrong password. Try again.";
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = "This user does not exist.";
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = "Database connection problem.";
|
||||
}
|
||||
} elseif (empty($_POST['user_name'])) {
|
||||
$this->errors[] = "Username field was empty.";
|
||||
} elseif (empty($_POST['user_password'])) {
|
||||
$this->errors[] = "Password field was empty.";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* perform the logout
|
||||
*/
|
||||
public function doLogout()
|
||||
{
|
||||
$_SESSION = array();
|
||||
session_destroy();
|
||||
$this->user_is_logged_in = false;
|
||||
$this->messages[] = "You have been logged out.";
|
||||
header('location:home.php');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* simply return the current state of the user's login
|
||||
* @return boolean user's login status
|
||||
*/
|
||||
public function isUserLoggedIn()
|
||||
{
|
||||
return $this->user_is_logged_in;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class registration
|
||||
*
|
||||
* handles the user registration
|
||||
* @author Panique
|
||||
* @link http://www.php-login.net
|
||||
* @link https://github.com/panique/php-login/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class Registration
|
||||
{
|
||||
/**
|
||||
* @var object $db_connection The database connection
|
||||
*/
|
||||
private $db_connection = null;
|
||||
/**
|
||||
* @var string $user_name The user's name
|
||||
*/
|
||||
private $user_name = "";
|
||||
/**
|
||||
* @var string $user_email The user's mail
|
||||
*/
|
||||
private $user_email = "";
|
||||
/**
|
||||
* @var string $user_password The user's password
|
||||
*/
|
||||
private $user_password = "";
|
||||
/**
|
||||
* @var string $user_password_hash The user's password hash
|
||||
*/
|
||||
private $user_password_hash = "";
|
||||
/**
|
||||
* @var boolean $registration_successful The user's registration success status
|
||||
*/
|
||||
public $registration_successful = false;
|
||||
/**
|
||||
* @var array $errors Collection of error messages
|
||||
*/
|
||||
public $errors = array();
|
||||
/**
|
||||
* @var array $messages Collection of success / neutral messages
|
||||
*/
|
||||
public $messages = array();
|
||||
|
||||
/**
|
||||
* the function "__construct()" automatically starts whenever an object of this class is created,
|
||||
* you know, when you do "$login = new Login();"
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (isset($_POST["register"])) {
|
||||
$this->registerNewUser();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handles the entire registration process. checks all error possibilities, and creates a new user in the database if
|
||||
* everything is fine
|
||||
*/
|
||||
private function registerNewUser()
|
||||
{
|
||||
if (empty($_POST['user_name'])) {
|
||||
$this->errors[] = "Empty Username";
|
||||
} elseif (empty($_POST['user_password_new']) || empty($_POST['user_password_repeat'])) {
|
||||
$this->errors[] = "Empty Password";
|
||||
} elseif ($_POST['user_password_new'] !== $_POST['user_password_repeat']) {
|
||||
$this->errors[] = "Password and password repeat are not the same";
|
||||
} elseif (strlen($_POST['user_password_new']) < 6) {
|
||||
$this->errors[] = "Password has a minimum length of 6 characters";
|
||||
} elseif (strlen($_POST['user_name']) > 64 || strlen($_POST['user_name']) < 2) {
|
||||
$this->errors[] = "Username cannot be shorter than 2 or longer than 64 characters";
|
||||
} elseif (!preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])) {
|
||||
$this->errors[] = "Username does not fit the name scheme: only a-Z and numbers are allowed, 2 to 64 characters";
|
||||
} elseif (empty($_POST['user_email'])) {
|
||||
$this->errors[] = "Email cannot be empty";
|
||||
} elseif (strlen($_POST['user_email']) > 64) {
|
||||
$this->errors[] = "Email cannot be longer than 64 characters";
|
||||
} elseif (!filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$this->errors[] = "Your email address is not in a valid email format";
|
||||
} elseif (!empty($_POST['user_name'])
|
||||
&& strlen($_POST['user_name']) <= 64
|
||||
&& strlen($_POST['user_name']) >= 2
|
||||
&& preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])
|
||||
&& !empty($_POST['user_email'])
|
||||
&& strlen($_POST['user_email']) <= 64
|
||||
&& filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)
|
||||
&& !empty($_POST['user_password_new'])
|
||||
&& !empty($_POST['user_password_repeat'])
|
||||
&& ($_POST['user_password_new'] === $_POST['user_password_repeat'])
|
||||
) {
|
||||
|
||||
// TODO: the above check is redundant, but from a developer's perspective it makes clear
|
||||
// what exactly we want to reach to go into this if-block
|
||||
|
||||
// creating a database connection
|
||||
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
|
||||
// if no connection errors (= working database connection)
|
||||
if (!$this->db_connection->connect_errno) {
|
||||
|
||||
// escapin' this, additionally removing everything that could be (html/javascript-) code
|
||||
$this->user_name = $this->db_connection->real_escape_string(htmlentities($_POST['user_name'], ENT_QUOTES));
|
||||
$this->user_email = $this->db_connection->real_escape_string(htmlentities($_POST['user_email'], ENT_QUOTES));
|
||||
|
||||
$this->user_password = $_POST['user_password_new'];
|
||||
|
||||
// crypt the user's password with the PHP 5.5's password_hash() function, results in a 60 character hash string
|
||||
// the PASSWORD_DEFAULT constant is defined by the PHP 5.5, or if you are using PHP 5.3/5.4, by the password hashing
|
||||
// compatibility library
|
||||
$this->user_password_hash = password_hash($this->user_password, PASSWORD_DEFAULT);
|
||||
|
||||
// check if user already exists
|
||||
$query_check_user_name = $this->db_connection->query("SELECT * FROM users WHERE user_name = '" . $this->user_name . "';");
|
||||
|
||||
if ($query_check_user_name->num_rows == 1) {
|
||||
$this->errors[] = "Sorry, that user name is already taken. Please choose another one.";
|
||||
} else {
|
||||
// write new users data into database
|
||||
$query_new_user_insert = $this->db_connection->query("INSERT INTO users (user_name, user_password_hash, user_email) VALUES('" . $this->user_name . "', '" . $this->user_password_hash . "', '" . $this->user_email . "');");
|
||||
|
||||
if ($query_new_user_insert) {
|
||||
$this->registration_successful = true;
|
||||
$this->messages[] = "Registration successful! Click here to <a href='index.php'>login</a>.";
|
||||
} else {
|
||||
$this->errors[] = "Sorry, your registration failed. Please go back and try again.";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = "An error has occured trying to connect to the database.";
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = "An unknown error occurred.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// Add an item to the cart
|
||||
function add_item($key, $quantity) {
|
||||
global $products;
|
||||
if ($quantity < 1) return;
|
||||
|
||||
// If item already exists in cart, update quantity
|
||||
if (isset($_SESSION['cart12'][$key])) {
|
||||
$quantity += $_SESSION['cart12'][$key]['qty'];
|
||||
update_item($key, $quantity);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add item
|
||||
$cost = $products[$key]['cost'];
|
||||
$total = $cost * $quantity;
|
||||
$item = array(
|
||||
'name' => $products[$key]['name'],
|
||||
'cost' => $cost,
|
||||
'qty' => $quantity,
|
||||
'total' => $total
|
||||
);
|
||||
$_SESSION['cart12'][$key] = $item;
|
||||
}
|
||||
|
||||
// Update an item in the cart
|
||||
function update_item($key, $quantity) {
|
||||
global $products;
|
||||
$quantity = (int) $quantity;
|
||||
if (isset($_SESSION['cart12'][$key])) {
|
||||
if ($quantity <= 0) {
|
||||
unset($_SESSION['cart12'][$key]);
|
||||
} else {
|
||||
$_SESSION['cart12'][$key]['qty'] = $quantity;
|
||||
$total = $_SESSION['cart12'][$key]['cost'] *
|
||||
$_SESSION['cart12'][$key]['qty'];
|
||||
$_SESSION['cart12'][$key]['total'] = $total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get cart subtotal
|
||||
function get_subtotal() {
|
||||
$subtotal = 0;
|
||||
foreach ($_SESSION['cart12'] as $item) {
|
||||
$subtotal += $item['total'];
|
||||
}
|
||||
$subtotal = number_format($subtotal, 2);
|
||||
return $subtotal;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Configuration file for: Database Connection
|
||||
* This is the place where your database login constants are saved
|
||||
*
|
||||
* For more info about constants please @see http://php.net/manual/en/function.define.php
|
||||
* If you want to know why we use "define" instead of "const" @see http://stackoverflow.com/q/2447791/1114320
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* database host, usually it's "127.0.0.1" or "localhost", some servers also need port info, like "127.0.0.1:8080"
|
||||
*/
|
||||
define("DB_HOST", "localhost");
|
||||
|
||||
/**
|
||||
* name of the database. please note: database and database table are not the same thing!
|
||||
*/
|
||||
define("DB_NAME", "login");
|
||||
|
||||
/**
|
||||
* user for your database. the user needs to have rights for SELECT, UPDATE, DELETE and INSERT.
|
||||
* by the way, it's bad style to use "root". In a real application you should create a database user
|
||||
* that fits your needs.
|
||||
*/
|
||||
define("DB_USER", "root");
|
||||
|
||||
/**
|
||||
* The password of the above user
|
||||
*/
|
||||
define("DB_PASS", "");
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 312 B |
|
After Width: | Height: | Size: 208 B |
|
After Width: | Height: | Size: 260 B |
|
After Width: | Height: | Size: 260 B |
|
After Width: | Height: | Size: 252 B |
|
After Width: | Height: | Size: 252 B |
|
After Width: | Height: | Size: 280 B |
|
After Width: | Height: | Size: 324 B |
|
After Width: | Height: | Size: 309 B |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
@@ -0,0 +1,80 @@
|
||||
/* main html tag css styling */
|
||||
body{
|
||||
background-color:#E0E0E0;
|
||||
}
|
||||
footer{
|
||||
width:100%;
|
||||
text-align: center;
|
||||
}
|
||||
aside{
|
||||
float:right;
|
||||
}
|
||||
header{
|
||||
background:url('../images/banner.png');
|
||||
height:100px;
|
||||
}
|
||||
header p{
|
||||
float:right;
|
||||
color:#E0E0E0;
|
||||
text-decoration:none;
|
||||
margin-right:1%;
|
||||
}
|
||||
/* child element styling */
|
||||
nav ul{
|
||||
list-style:none;
|
||||
padding:0;
|
||||
text-align:center;
|
||||
}
|
||||
nav ul li{
|
||||
display:inline;
|
||||
margin-right:2%;
|
||||
}
|
||||
nav ul li:hover{
|
||||
text-decoration:underline;
|
||||
color:#FF0000;
|
||||
}
|
||||
section h1{
|
||||
text-align:center;
|
||||
}
|
||||
ul li a{
|
||||
text-decoration: none;
|
||||
}
|
||||
/* class elements styling */
|
||||
div.content{
|
||||
width:75%;
|
||||
margin-left:13%;
|
||||
}
|
||||
div.shopping-cart{
|
||||
float:right;
|
||||
|
||||
}
|
||||
section.login{
|
||||
width:50%;
|
||||
float:right;
|
||||
margin-right:25%;
|
||||
}
|
||||
a.sign-in{
|
||||
float:right;
|
||||
color:#E0E0E0;
|
||||
text-decoration:none;
|
||||
margin-right:1%;
|
||||
}
|
||||
a.sign-in:hover{
|
||||
text-decoration:none;
|
||||
border-bottom: 1px solid #FF0000;
|
||||
}
|
||||
|
||||
/* id element styling */
|
||||
#itemRow{
|
||||
width:70%;
|
||||
height:30%;
|
||||
margin-left:13%;
|
||||
}
|
||||
#iteminfo{
|
||||
font-size:14px;
|
||||
color: rgb(64,64,64);
|
||||
}
|
||||
div#shopping-cart{
|
||||
text-align:left;
|
||||
padding-left:40%;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
$fileName = basename(__FILE__, ".php"); //grabs the file name and drops the extension
|
||||
$fileName = ucwords($fileName); //capitalizes the first letter of every word
|
||||
include("templates/header.php");
|
||||
?>
|
||||
|
||||
<section>
|
||||
<h1>Welcome to Computers R Us!</h1>
|
||||
<div class="ui-widget-content content" id="content">
|
||||
<p>Welcome to Computers R Us, sellers of only the best computer hardware. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut quam massa, placerat eu tellus vitae, blandit porttitor metus. Nullam purus leo, pulvinar sed neque vel, laoreet molestie libero. Suspendisse potenti. Mauris fermentum, urna non tincidunt luctus, diam elit lobortis magna, sit amet tincidunt odio diam vitae purus. Duis ac lacus tempor quam eleifend ultricies. Aenean ut aliquet erat, quis vestibulum libero. Aliquam viverra fermentum nibh sed tempor. Vestibulum gravida nunc augue, eget sollicitudin nulla gravida et.</p>
|
||||
<p> Donec convallis tellus tortor, sagittis pharetra arcu rutrum eu. Vestibulum vitae arcu in dui euismod congue. Ut nibh est, elementum eget malesuada in, convallis vitae quam.Nunc quis vulputate dolor. Morbi scelerisque ligula eu dolor ornare viverra. Aenean sed ornare ligula, sed suscipit ipsum. Suspendisse potenti. Pellentesque ut molestie eros, id gravida lorem. Sed interdum sit amet purus id pulvinar. Nam fermentum tortor ac lorem ultricies accumsan.</p>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
<footer>
|
||||
<h5>© 2013-2014 Computers R Us Inc.</h5>
|
||||
</footer>
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 361 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A simple, clean and secure PHP Login Script
|
||||
*
|
||||
* MINIMAL VERSION
|
||||
* (check the website / github / facebook for other versions)
|
||||
*
|
||||
* A simple PHP Login Script.
|
||||
* Uses PHP SESSIONS, modern password-hashing and salting
|
||||
* and gives the basic functions a proper login system needs.
|
||||
*
|
||||
* Please remember: this is just the minimal version of the login script, so if you need a more
|
||||
* advanced version, have a look on the github repo. there are / will be better versions, including
|
||||
* more functions and/or much more complex code / file structure. buzzwords: MVC, dependency injected,
|
||||
* one shared database connection, PDO, prepared statements, PSR-0/1/2 and documented in phpDocumentor style
|
||||
*
|
||||
* @package php-login
|
||||
* @author Panique
|
||||
* @link https://github.com/panique/php-login/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
// checking for minimum PHP version
|
||||
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
|
||||
exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !");
|
||||
} else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
// if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php
|
||||
// (this library adds the PHP 5.5 password hashing functions to older versions of PHP)
|
||||
require_once("libraries/password_compatibility_library.php");
|
||||
}
|
||||
|
||||
// include the configs / constants for the database connection
|
||||
require_once("config/db.php");
|
||||
|
||||
// load the login class
|
||||
require_once("classes/Login.php");
|
||||
|
||||
// create a login object. when this object is created, it will do all login/logout stuff automatically
|
||||
// so this single line handles the entire login process. in consequence, you can simply ...
|
||||
$login = new Login();
|
||||
|
||||
// ... ask if we are logged in here:
|
||||
if ($login->isUserLoggedIn() == true) {
|
||||
// the user is logged in. you can do whatever you want here.
|
||||
// for demonstration purposes, we simply show the "you are logged in" view.
|
||||
include("home.php");
|
||||
|
||||
} else {
|
||||
// the user is not logged in. you can do whatever you want here.
|
||||
// for demonstration purposes, we simply show the "you are not logged in" view.
|
||||
include("views/sign-in.php");
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
$(function(){
|
||||
$("#draggable").draggable();
|
||||
});
|
||||
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
/**
|
||||
* A Compatibility library with PHP 5.5's simplified password hashing API.
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@php.net>
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @copyright 2012 The Authors
|
||||
*/
|
||||
|
||||
if (!defined('PASSWORD_DEFAULT')) {
|
||||
|
||||
define('PASSWORD_BCRYPT', 1);
|
||||
define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
|
||||
|
||||
/**
|
||||
* Hash the password using the specified algorithm
|
||||
*
|
||||
* @param string $password The password to hash
|
||||
* @param int $algo The algorithm to use (Defined by PASSWORD_* constants)
|
||||
* @param array $options The options for the algorithm to use
|
||||
*
|
||||
* @return string|false The hashed password, or false on error.
|
||||
*/
|
||||
function password_hash($password, $algo, array $options = array()) {
|
||||
if (!function_exists('crypt')) {
|
||||
trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
if (!is_string($password)) {
|
||||
trigger_error("password_hash(): Password must be a string", E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
if (!is_int($algo)) {
|
||||
trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
switch ($algo) {
|
||||
case PASSWORD_BCRYPT:
|
||||
// Note that this is a C constant, but not exposed to PHP, so we don't define it here.
|
||||
$cost = 10;
|
||||
if (isset($options['cost'])) {
|
||||
$cost = $options['cost'];
|
||||
if ($cost < 4 || $cost > 31) {
|
||||
trigger_error(sprintf("password_hash(): Invalid bcrypt cost parameter specified: %d", $cost), E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// The length of salt to generate
|
||||
$raw_salt_len = 16;
|
||||
// The length required in the final serialization
|
||||
$required_salt_len = 22;
|
||||
$hash_format = sprintf("$2y$%02d$", $cost);
|
||||
break;
|
||||
default:
|
||||
trigger_error(sprintf("password_hash(): Unknown password hashing algorithm: %s", $algo), E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
if (isset($options['salt'])) {
|
||||
switch (gettype($options['salt'])) {
|
||||
case 'NULL':
|
||||
case 'boolean':
|
||||
case 'integer':
|
||||
case 'double':
|
||||
case 'string':
|
||||
$salt = (string) $options['salt'];
|
||||
break;
|
||||
case 'object':
|
||||
if (method_exists($options['salt'], '__tostring')) {
|
||||
$salt = (string) $options['salt'];
|
||||
break;
|
||||
}
|
||||
case 'array':
|
||||
case 'resource':
|
||||
default:
|
||||
trigger_error('password_hash(): Non-string salt parameter supplied', E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
if (strlen($salt) < $required_salt_len) {
|
||||
trigger_error(sprintf("password_hash(): Provided salt is too short: %d expecting %d", strlen($salt), $required_salt_len), E_USER_WARNING);
|
||||
return null;
|
||||
} elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt)) {
|
||||
$salt = str_replace('+', '.', base64_encode($salt));
|
||||
}
|
||||
} else {
|
||||
$buffer = '';
|
||||
$buffer_valid = false;
|
||||
if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
|
||||
$buffer = mcrypt_create_iv($raw_salt_len, MCRYPT_DEV_URANDOM);
|
||||
if ($buffer) {
|
||||
$buffer_valid = true;
|
||||
}
|
||||
}
|
||||
if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) {
|
||||
$buffer = openssl_random_pseudo_bytes($raw_salt_len);
|
||||
if ($buffer) {
|
||||
$buffer_valid = true;
|
||||
}
|
||||
}
|
||||
if (!$buffer_valid && is_readable('/dev/urandom')) {
|
||||
$f = fopen('/dev/urandom', 'r');
|
||||
$read = strlen($buffer);
|
||||
while ($read < $raw_salt_len) {
|
||||
$buffer .= fread($f, $raw_salt_len - $read);
|
||||
$read = strlen($buffer);
|
||||
}
|
||||
fclose($f);
|
||||
if ($read >= $raw_salt_len) {
|
||||
$buffer_valid = true;
|
||||
}
|
||||
}
|
||||
if (!$buffer_valid || strlen($buffer) < $raw_salt_len) {
|
||||
$bl = strlen($buffer);
|
||||
for ($i = 0; $i < $raw_salt_len; $i++) {
|
||||
if ($i < $bl) {
|
||||
$buffer[$i] = $buffer[$i] ^ chr(mt_rand(0, 255));
|
||||
} else {
|
||||
$buffer .= chr(mt_rand(0, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
$salt = str_replace('+', '.', base64_encode($buffer));
|
||||
}
|
||||
$salt = substr($salt, 0, $required_salt_len);
|
||||
|
||||
$hash = $hash_format . $salt;
|
||||
|
||||
$ret = crypt($password, $hash);
|
||||
|
||||
if (!is_string($ret) || strlen($ret) <= 13) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about the password hash. Returns an array of the information
|
||||
* that was used to generate the password hash.
|
||||
*
|
||||
* array(
|
||||
* 'algo' => 1,
|
||||
* 'algoName' => 'bcrypt',
|
||||
* 'options' => array(
|
||||
* 'cost' => 10,
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @param string $hash The password hash to extract info from
|
||||
*
|
||||
* @return array The array of information about the hash.
|
||||
*/
|
||||
function password_get_info($hash) {
|
||||
$return = array(
|
||||
'algo' => 0,
|
||||
'algoName' => 'unknown',
|
||||
'options' => array(),
|
||||
);
|
||||
if (substr($hash, 0, 4) == '$2y$' && strlen($hash) == 60) {
|
||||
$return['algo'] = PASSWORD_BCRYPT;
|
||||
$return['algoName'] = 'bcrypt';
|
||||
list($cost) = sscanf($hash, "$2y$%d$");
|
||||
$return['options']['cost'] = $cost;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the password hash needs to be rehashed according to the options provided
|
||||
*
|
||||
* If the answer is true, after validating the password using password_verify, rehash it.
|
||||
*
|
||||
* @param string $hash The hash to test
|
||||
* @param int $algo The algorithm used for new password hashes
|
||||
* @param array $options The options array passed to password_hash
|
||||
*
|
||||
* @return boolean True if the password needs to be rehashed.
|
||||
*/
|
||||
function password_needs_rehash($hash, $algo, array $options = array()) {
|
||||
$info = password_get_info($hash);
|
||||
if ($info['algo'] != $algo) {
|
||||
return true;
|
||||
}
|
||||
switch ($algo) {
|
||||
case PASSWORD_BCRYPT:
|
||||
$cost = isset($options['cost']) ? $options['cost'] : 10;
|
||||
if ($cost != $info['options']['cost']) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a password against a hash using a timing attack resistant approach
|
||||
*
|
||||
* @param string $password The password to verify
|
||||
* @param string $hash The hash to verify against
|
||||
*
|
||||
* @return boolean If the password matches the hash
|
||||
*/
|
||||
function password_verify($password, $hash) {
|
||||
if (!function_exists('crypt')) {
|
||||
trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
$ret = crypt($password, $hash);
|
||||
if (!is_string($ret) || strlen($ret) != strlen($hash) || strlen($ret) <= 13) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$status = 0;
|
||||
for ($i = 0; $i < strlen($ret); $i++) {
|
||||
$status |= (ord($ret[$i]) ^ ord($hash[$i]));
|
||||
}
|
||||
|
||||
return $status === 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A simple, clean and secure PHP Login Script
|
||||
*
|
||||
* MINIMAL VERSION
|
||||
* (check the website / github / facebook for other versions)
|
||||
*
|
||||
* A simple PHP Login Script.
|
||||
* Uses PHP SESSIONS, modern password-hashing and salting
|
||||
* and gives the basic functions a proper login system needs.
|
||||
*
|
||||
* Please remember: this is just the minimal version of the login script, so if you need a more
|
||||
* advanced version, have a look on the github repo. there are / will be better versions, including
|
||||
* more functions and/or much more complex code / file structure. buzzwords: MVC, dependency injected,
|
||||
* one shared database connection, PDO, prepared statements, PSR-0/1/2 and documented in phpDocumentor style
|
||||
*
|
||||
* @package php-login
|
||||
* @author Panique
|
||||
* @link https://github.com/panique/php-login/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
// checking for minimum PHP version
|
||||
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
|
||||
exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !");
|
||||
} else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
// if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php
|
||||
// (this library adds the PHP 5.5 password hashing functions to older versions of PHP)
|
||||
require_once("libraries/password_compatibility_library.php");
|
||||
}
|
||||
|
||||
// include the configs / constants for the database connection
|
||||
require_once("config/db.php");
|
||||
|
||||
// load the registration class
|
||||
require_once("classes/Registration.php");
|
||||
|
||||
// create the registration object. when this object is created, it will do all registration stuff automaticly
|
||||
// so this single line handles the entire registration process.
|
||||
$registration = new Registration();
|
||||
|
||||
// showing the register view (with the registration form, and messages/errors)
|
||||
include("views/register.php");
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// Start session management with a persistent cookie
|
||||
$lifetime = 60 * 60 * 24 * 14; // 2 weeks in seconds
|
||||
// $lifetime = 0; // per-session cookie
|
||||
session_set_cookie_params($lifetime, '/');
|
||||
session_start();
|
||||
|
||||
// Create a cart array if needed
|
||||
if (empty($_SESSION['cart12'])) $_SESSION['cart12'] = array();
|
||||
|
||||
// Create a table of products
|
||||
$products = array();
|
||||
$products['D2400'] = array('name' => 'Dimension 2400', 'cost' => '149.50');
|
||||
$products['AG3'] = array('name' => 'Macintosh G3', 'cost' => '199.50');
|
||||
$products['DE510'] = array('name' => 'Dimension E510', 'cost' => '299.50');
|
||||
|
||||
// Include cart functions
|
||||
require_once('config/cart.php');
|
||||
|
||||
// Get the action to perform
|
||||
if (isset($_POST['action'])) {
|
||||
$action = $_POST['action'];
|
||||
} else if (isset($_GET['action'])) {
|
||||
$action = $_GET['action'];
|
||||
} else {
|
||||
$action = 'show_add_item';
|
||||
}
|
||||
|
||||
// Add or update cart as needed
|
||||
switch($action) {
|
||||
case 'add':
|
||||
add_item($_POST['productkey'], $_POST['itemqty']);
|
||||
include("cart-view.php");
|
||||
break;
|
||||
case 'update':
|
||||
$new_qty_list = $_POST['newqty'];
|
||||
foreach($new_qty_list as $key => $qty) {
|
||||
if ($_SESSION['cart12'][$key]['qty'] != $qty) {
|
||||
update_item($key, $qty);
|
||||
}
|
||||
}
|
||||
include('cart-view.php');
|
||||
break;
|
||||
case 'show_cart':
|
||||
include('cart-view.php');
|
||||
break;
|
||||
case 'show_add_item':
|
||||
include('store.php');
|
||||
break;
|
||||
case 'empty_cart':
|
||||
unset($_SESSION['cart12']);
|
||||
include('cart-view.php');
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
$fileName = basename(__FILE__, ".php"); //grabs the file name and drops the extension
|
||||
$fileName = ucwords($fileName); //capitalizes the first letter of every word
|
||||
include("templates/header.php");
|
||||
|
||||
$products = array();
|
||||
$products['D2400'] = array('name' => 'Dimension 2400', 'cost' => '149.50');
|
||||
$products['AG3'] = array('name' => 'Macintosh G3', 'cost' => '199.50');
|
||||
$products['DE510'] = array('name' => 'Dimension E510', 'cost' => '299.50');
|
||||
?>
|
||||
<div class="row-fluid" id="itemRow">
|
||||
<div class="span4">
|
||||
<img src="images/g3.jpg" height="150px" width="125px" title="Macintosh Power PC G3"/>
|
||||
<ul id="iteminfo">
|
||||
<li>9 gigabyte hard disk drive</li>
|
||||
<li>330 MHz processor</li>
|
||||
<li>Mac OS 9 compatible</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<img src="images/2400.jpg" height="150px" width="125px" title="Dell Dimension 2400" />
|
||||
<ul id="iteminfo">
|
||||
<li>50 gigabyte hard disk drive</li>
|
||||
<li>3.0 GHz processor</li>
|
||||
<li>Windows XP compatible</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<img src="images/computers.jpg" height="200px" width="250px" />
|
||||
</div>
|
||||
</div><!-- end first row -->
|
||||
<div class="row-fluid" id="itemRow">
|
||||
<div class="span4">
|
||||
<img src="images/computers.jpg" height="200px" width="250px" />
|
||||
</div>
|
||||
<div class="span4">
|
||||
<img src="images/computers.jpg" height="200px" width="250px" />
|
||||
</div>
|
||||
<?php if(isset($_SESSION['user_name'])) : ?><!-- begin add item cart -->
|
||||
<div class="shopping-cart span4">
|
||||
<h1>Add Item</h1>
|
||||
<form action="shopping-cart-index.php?action=add" method="post">
|
||||
<input type="hidden" name="action" value="add"/>
|
||||
|
||||
<label>Name:</label>
|
||||
<select name="productkey">
|
||||
<?php foreach($products as $key => $product) :
|
||||
$cost = number_format($product['cost'], 2);
|
||||
$name = $product['name'];
|
||||
$item = $name . ' ($' . $cost . ')';
|
||||
?>
|
||||
<option value="<?php echo $key; ?>">
|
||||
<?php echo $item; ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select><br />
|
||||
|
||||
<label>Quantity:</label>
|
||||
<select name="itemqty">
|
||||
<?php for($i = 1; $i <= 10; $i++) : ?>
|
||||
<option value="<?php echo $i; ?>">
|
||||
<?php echo $i; ?>
|
||||
</option>
|
||||
<?php endfor; ?>
|
||||
</select><br />
|
||||
|
||||
<label> </label>
|
||||
<input type="submit" value="Add Item"/>
|
||||
</form>
|
||||
<p><a href="shopping-cart-index.php?action=show_cart">View Cart</a></p>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="shopping-cart span4">Sign in to view your items.</div>
|
||||
<?php endif; ?><!-- end add item cart -->
|
||||
</div><!-- end second row -->
|
||||
<div class="row-fluid" id="itemRow">
|
||||
<div class="span4">
|
||||
<img src="images/computers.jpg" height="200px" width="250px" />
|
||||
</div>
|
||||
<div class="span4">
|
||||
<img src="images/computers.jpg" height="200px" width="250px" />
|
||||
</div>
|
||||
<div class="span4">
|
||||
<img src="images/computers.jpg" height="200px" width="250px" />
|
||||
</div>
|
||||
</div><!-- end third row -->
|
||||
</body>
|
||||
<footer>
|
||||
<h5>© 2013-2014 Computers R Us Inc.</h5>
|
||||
</footer>
|
||||
</html>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
session_start();
|
||||
if(isset($_SESSION['user_name']))
|
||||
$user = "<p>Welcome, " . $_SESSION['user_name'] . ". <a class='sign-in' href='index.php?logout'>Logout</a>.</p>";
|
||||
else
|
||||
$user = "<a class='sign-in' href='index.php'>Sign In</a>";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title><?php echo $fileName; ?> | Computers R Us</title>
|
||||
<link rel="shortcut icon" href="images/favico.ico">
|
||||
<link href="css/black-tie/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css" /><!-- jQuery UI link -->
|
||||
<!-- bootstrap responsive css link -->
|
||||
<link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
|
||||
<!-- custom css page -->
|
||||
<link href="css/main.css" rel="stylesheet"/>
|
||||
<!-- jQuery scripts -->
|
||||
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
|
||||
<script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
|
||||
<!-- custom scripts -->
|
||||
<script type="text/javascript" src="js/main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header><?php echo $user;?></header>
|
||||
<nav class="ui-widget-header">
|
||||
<ul>
|
||||
<li><a href="home.php">Home</a></li>
|
||||
<li><a href="store.php">Store</a></li>
|
||||
<li><a href="about-us.php">About Us</a></li>
|
||||
</ul>
|
||||
</nav><!-- end nav -->
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
if($fileName == "Sign In"){
|
||||
$signed = "<a class='sign-in' href='register.php'>Register Now!</a>";
|
||||
}elseif($fileName == "Register"){
|
||||
$signed = "<a class='sign-in' href='index.php'>Sign In</a>";
|
||||
}else{
|
||||
$signed = "<a class='sign-in' href='#' >We done goofed...</a>";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<body>
|
||||
<section class="login">
|
||||
<title><?php echo $fileName; ?> | Computers R Us</title>
|
||||
<link rel="shortcut icon" href="images/favico.ico">
|
||||
<link href="css/main.css" rel="stylesheet"/>
|
||||
<link href="css/black-tie/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css" />
|
||||
<style type="text/css">
|
||||
a {text-decoration: none; }
|
||||
h5 a:hover{text-decoration:underline; }
|
||||
.login{
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
<header><?php echo $signed; ?></header>
|
||||
<nav class="ui-widget-header">
|
||||
<ul>
|
||||
<li><a href="home.php">Home</a></li>
|
||||
<li><a href="store.php">Store</a></li>
|
||||
<li><a href="about-us.php">About Us</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
@@ -0,0 +1,4 @@
|
||||
<Files ~ "\.(htaccess|php)$">
|
||||
order allow,deny
|
||||
deny from all
|
||||
</Files>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
$fileName = basename(__FILE__, ".php"); //grabs the file name and drops the extension
|
||||
$fileName = ucwords($fileName); //capitalizes the first letter of every word
|
||||
include("templates/signed-header.php");
|
||||
?>
|
||||
<form method="post" action="register.php" name="registerform">
|
||||
<label for="login_input_username">Username</label>
|
||||
<input id="login_input_username" type="text" pattern="[a-zA-Z0-9]{2,64}" name="user_name" required />
|
||||
<label for="login_input_email">User email</label>
|
||||
<input id="login_input_email" class="login_input" type="email" name="user_email" required />
|
||||
<label for="login_input_password_new">Password</label>
|
||||
<input id="login_input_password_new" class="login_input" type="password" name="user_password_new" pattern=".{6,}" required autocomplete="off" />
|
||||
<label for="login_input_password_repeat">Repeat password</label>
|
||||
<input id="repeatPassword" class="login_input" type="password" name="user_password_repeat" pattern=".{6,}" required autocomplete="off" />
|
||||
<input type="submit" name="register" value="Register" />
|
||||
</form>
|
||||
<?php // show negative messages
|
||||
if ($registration->errors) {
|
||||
foreach ($registration->errors as $error) {
|
||||
echo $error;
|
||||
}
|
||||
}
|
||||
// show positive messages
|
||||
if ($registration->messages) {
|
||||
foreach ($registration->messages as $message) {
|
||||
echo $message;
|
||||
}
|
||||
}
|
||||
?>
|
||||
</section>
|
||||
</body>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
$fileName = basename(__FILE__, ".php"); //grabs the file name and drops the extension
|
||||
$fileName = str_replace('-', ' ', $fileName); //replaces all hypens with a space
|
||||
$fileName = ucwords($fileName); //capitalizes the first letter of every word
|
||||
include("templates/signed-header.php")
|
||||
?>
|
||||
<form method="post" action="index.php" name="loginform">
|
||||
<label for="login_input_username">Username</label>
|
||||
<input id="login_input_username" type="text" name="user_name" required />
|
||||
<label for="login_input_password">Password</label>
|
||||
<input id="login_input_password" type="password" name="user_password" required />
|
||||
<input type="submit" name="login" value="Log in" />
|
||||
</form>
|
||||
|
||||
<?php
|
||||
// show negative messages
|
||||
if ($login->errors) {
|
||||
foreach ($login->errors as $error) {
|
||||
echo $error;
|
||||
}
|
||||
}
|
||||
|
||||
// show positive messages
|
||||
if ($login->messages) {
|
||||
foreach ($login->messages as $message) {
|
||||
echo $message;
|
||||
}
|
||||
}
|
||||
?>
|
||||
</section>
|
||||
</body>
|
||||