<?php session_start(); ?>
<?php  require_once("connect.php"); ?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head>

<?php

include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
$err_message=array("","驗證碼錯誤!","帳號或密碼有誤！");


if ($_POST['action'] == "dologin" ) {

	if ($securimage->check($_POST['captcha_code']) == false) {
	    $_SESSION['login_state']="no";
		$err_code=1;
	} else {
		$account=$_POST['account'];
		$password=$_POST['password'];

		$sql="select * from bkstage_user where account='$account' and password='$password'";
//	echo $sql;
		$result=mysql_query($sql);

		$num_rows=mysql_num_rows($result);
		if ($num_rows == 0) {
			$_SESSION['login_state']="no";
			$err_code=2;
		} else {
			$_SESSION['login_state']="yes";
			echo "<script language='JavaScript'>window.location.href='index.php';</script>";
		}  // end  if ($num_rows==0) {
	} //if ($securimage->check($_POST['captcha_code'])
}// end if ($_POST['action']=="dologin") {


?>




<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="402" height="167" border="1" align="center" cellpadding="2" cellspacing="2">
  <tr>
    <td width="385" height="161" align="center" bgcolor="#DFDFDF">
    
    <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
        <p>&nbsp;        </p>
        <p>
          <input type="hidden" name="action" value="dologin">
        </p>
        <p>
          <label for="account"></label>
        帳號：
        <input type="text" name="account" id="account" />
    </p>
      <p>
        <label for="password">密碼：</label>
        <input type="password" name="password" id="password" />
      </p>
      <p>
        <input type="text" name="captcha_code" size="10" maxlength="6" />
        <img width="140" id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /> [ <a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">換一張</a> ]</p>
      <p>
        <input type="submit" name="confirm" id="confirm" value="送出" />
        　
        <input type="reset" name="cancel" id="cancel" value="重設" />
      </p>
    </form>
    

<?php
//	if ($_SESSION['login_state']=='no') echo "<tr><td align=center><font color=red>".$err_message[$err_code]."</font></td></tr>";
	if ($_SESSION['login_state']=='no') echo "<font size=h3 color=red align=center>".$err_message[$err_code]."</font>";
?>
    </td>
  </tr>

</table>

</body>
</html>