Location: PHPKode > projects > Quick Guestbook > quicktalk/qtg_login.php
<?php

/**
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license.  If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @package    QuickTalk Guestbook
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2009-2012 The PHP Group
* @version    2.5 build:20100731
*/

session_start();
require_once('bin/qtg_init.php');

// INITIALISE

$ok = '';
$usr = '';
$pwd = '';
QThttpvar('ok usr pwd', 'str str str');
$pg_url='qtg_login.php';
$bJava=false;

// --------
// SUBMITTED for log-in
// --------

if ( !empty($ok) )
{
  // CHECK FORM VALUE

  if ( get_magic_quotes_gpc() ) $usr = stripslashes($usr);
  if ( !QTislogin($usr,2) ) $error = $L['Username'].' '.$L['E_invalid'];
  if ( !QTispassword($pwd,2) ) $error = $L['Password'].' '.$L['E_invalid'];

  // check login
  if ( empty($error) )
  {
    if ( ($usr!=$qtg_user) && ($usr!=$qtg_user_2) ) $error=$L['E_access_denied'];
  }
  // check pwd
  if ( empty($error) )
  {
    if ( ($usr==$qtg_user) && ($pwd!=$qtg_pwd) ) $error=$L['E_access_denied'];
    if ( ($usr==$qtg_user_2) && ($pwd!=$qtg_pwd_2) ) $error=$L['E_access_denied'];
  }

  // execute
  if ( empty($error) )
  {
  $_SESSION['qtgAuth'] = 'yes';
  include('qtg_p_header.php');
  echo '
  <div id="login">
  <h1>',$L['Login'],' ',$usr,'</h1>
  <p>&nbsp;</p>
  <div class="backbutton"><span class="backbutton"><a id="exiturl" class="button" href="qtg_adm.php">',$L['Return_administration'],'</a></span></div>
  </div>
  <script type="text/javascript">
  <!--
  setTimeout(\'window.location=document.getElementById("exiturl").href\',1000);
  -->
  </script>
  ';
  include('qtg_p_footer.php');
  exit;
  }
}

// --------
// SUBMITTED for log-out
// --------

if ( isset($_GET['a']) ) {
if ( $_GET['a']=='out' ) {
  session_destroy();  
  require_once('bin/qtg_init.php');
  $_SESSION['qtgAuth']='N';
  include('qtg_p_header.php');  
  echo '
  <h1>',$L['Logout'],'</h1><br/><br/>',$qtg_back,'
  <script type="text/javascript">
  <!--
  setTimeout(\'window.location=document.getElementById("exiturl").href\',1000);
  -->
  </script>
  ';
  include('qtg_p_footer.php');
  exit;
}}

// --------
// HTML
// --------

$strHeadScript = '<script type="text/javascript">
<!--
function ValidateForm(theForm)
{
  if (theForm.usr.value.length==0 || theForm.pwd.value.length==0) { alert(qtHtmldecode(\''.$L['E_mandatory'].'\')); return false; }
  return null;
}
-->
</script>
';

include('qtg_p_header.php');

echo '<h1>',$L['Login'],'</h1>
<div class="login">
<form method="post" action="',Href('qtg_login.php'),'" onsubmit="return ValidateForm(this)">
<p class="login"><label for="usr">',$L['Username'],'</label> <input type="text" id="usr" name="usr" size="20" maxlength="24" value="',$usr,'"/></p>
<p class="login"><label for="pwd">',$L['Password'],'</label> <input type="password" id="pwd" name="pwd" size="20" maxlength="24"/></p>
<p class="login">',( !empty($error) ? '<span class="error">'.$error.'</span> ' : ''),'<input type="submit" name="ok" value="',$L['Login'],'"/></p>
</form>
</div>
<p>&nbsp;</p>',$qtg_back,'
';

$strFooterAddScript = '<script type="text/javascript">
<!--
document.getElementById("usr").focus();
if ( document.getElementById("usr").value.length>1 ) { document.getElementById("pwd").focus(); }
-->
</script>
';

include('qtg_p_footer.php');

?>
Return current item: Quick Guestbook