佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 899|回复: 2

PHP 登入问题!!!

[复制链接]
发表于 6-7-2008 01:38 PM | 显示全部楼层 |阅读模式
嗨!各位PHP高手们,请问我要如何做到当用户输入正确的Username,但不正确的密码;我要在我的Database Table field Times”增加1,直到3(用户输入三次错误的密码),
Database Table field Locked”就等于Yes。这时,就算用户输入正确的Username 和密码也不能登入了….希望各位帮帮我,万分谢意。


我的Table
和Coding大概是这样子的;如下:



ID     Userid      Password    Locked   Times
1       demo        demo                No              0


index.php
<?php require_once('Connections/test.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "success.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_test, $test);
  
  $LoginRS__query=sprintf("SELECT Userid, Password FROM addmen WHERE Userid=%s AND Password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
   
  $LoginRS = mysql_query($LoginRS__query, $test) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
   
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
     $error1="登入错误!!!<br>";
   $error2="Wrong Username/Password!!!";  
  }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" c />
<title>TESTING</title>
</head>

<body>
<form id="frmMember" name="frmMember" method="POST" action="<?php echo $loginFormAction; ?>">
  Username:
  <label>
  <input type="text" name="username" id="username" />
  </label>
  <br />
  <br />
  Password:
  <label>
  <input type="password" name="password" id="password" />
  </label>
  <p>
    <label>
    <input type="submit" name="button" id="button" value="Login" />
    </label>
    <?php echo $error1;?><?php echo $error2;?><br />
  </p>
</form>
</body>
</html>



success.php
<?php
if (!isset($_SESSION)) {
  session_start();
}


$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_d;
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
   $isValid = False;

  if (!empty($UserName)) {

    $arrUsers = Explode(",", $strUsers);
    $arrGroups = Explode(",", $strGroups);
    if (in_array($UserName, $arrUsers)) {
      $isValid = true;
    }
    if (in_array($UserGroup, $arrGroups)) {
      $isValid = true;
    }
    if (($strUsers == "") && true) {
      $isValid = true;
    }
  }
  return $isValid;
}
$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo);
  exit;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" c />
<title>SUCCESS</title>
</head>
<body>
<p>Login Successful!!</p>
<p>
  <label><a href="<?php echo $logoutAction ?>">Log out</a>  </label>
</p>
</body>
</html>

回复

使用道具 举报


ADVERTISEMENT

发表于 6-7-2008 02:41 PM | 显示全部楼层
你自己都注明了,登入失败时就+1。 用 update 咯
但是记得成功login 后就得 reset 那个 field。

登入时的 select 加多一个 condition,那个 field 的数目必须是小过 3。

以上是用你的 logic 想出来的方法。
回复

使用道具 举报

 楼主| 发表于 6-7-2008 03:32 PM | 显示全部楼层
谢谢您!我解决了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 24-12-2025 03:09 AM , Processed in 0.125321 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表