Location: PHPKode > scripts > Quotations Database > quotations-database/admin/include/login.php

:::: Quotations Database ::::
PHP & MySQL application that stores quotations and author information, 
allows scheduling for 'quote of the day' and weekly themes.
Includes an administration interface to allow for easy updates and maintenance.
Copyright (C) 2009  Robert Temple

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

You can contact the author at hide@address.com
Please do not remove the author, copyright, or license info.

// Connect  to database
include "connect.php";
// If login form was submitted, try to log on user:
if ($_POST['submit']) {

$Username = $_POST['Username'];
$Password = md5($_POST['Password']);

$query = "SELECT * from UsersTBL WHERE Username='$Username' AND Password='$Password'";
$result = mysql_query($query) or die ( mysql_error() );

// If login fails, set error message cookie:
if (mysql_num_rows($result)!= 1) { 
setcookie("Login_Error", "Login failed. Username and password incorrect.", time()+(600), "/"); 
} else  

// Login success! Set Quotation_login cookie to be used to verify login:
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
setcookie("Quotation_login", "Yes", time()+(84600), "/");  


// Finally, redirect user to admin page:	
header("Location: ../index.php");	
} else {

// Form not submitted yet, show login page:


<title> Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="../../quotation.css" rel="stylesheet" type="text/css">

<body OnLoad="document.form_login.Username.focus();">
<table width="700" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#000000">
<table width="698" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF">
        <Td colspan="2" bgcolor="#FFFFCC"> <br />
         <span  class="header">Quotations Database- Login Page</span><br />
        <Td class="bodyBoldRed"><? echo $_COOKIE['Login_Error'] ?> </Td>
    <td valign="top"><form name="form_login" method="post" action="<? echo $PHP_SELF; ?>">
      <table width="300" align="center" cellpadding="2">
          <td align="right" class="bodyCopy"><p>Username:</p></td>
          <td><input type="text" name="Username" id="Username"></td>
          <td align="right" class="bodyCopy"><p>Password:</p></td>
          <td><input type="password" name="Password" id="Password"></td>
          <td colspan=2 align=center><input name="submit" type="submit" class="bodyCopy" value="Log in"></td>
Return current item: Quotations Database