即使用户有效,页面也不会在登录时接受用户

时间:2012-05-22 17:17:41

标签: php authentication login dreamweaver

我目前在网站上的用户登录功能方面遇到了一些问题。我在index.php页面上创建了一个登录表单表,并告诉它如果登录有效则转到userindex.php,如果不是则登录到loginfail.html。然后使用dreamweavers页面授权工具我保护页面userindex.php并告诉它将未经授权的用户重定向回index.php

我遇到的问题是,一旦有人输入正确的用户名和密码详细信息并按下提交,他们就会被发送到index.php。就像它们被发送到userindex.php然后没有被授权一样。但是,在登录后输入userindex.php的地址会显示页面已完成,其中包含用户信息,就像它们已被批准一样。

以下是有关此用户登录问题的两个页面的代码

的index.php

    <?php
        // *** Validate request to login to this site.
        if (!isset($_SESSION)) {
          session_start();
        }

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

        if (isset($_POST['UsernmaeBox'])) {
          $loginUsername=$_POST['UsernmaeBox'];
          $password=$_POST['PasswordBox'];
          $MM_fldUserAuthorization = "";
          $MM_redirectLoginSuccess = "Userindex.php";
          $MM_redirectLoginFailed = "loginfail.html";
          $MM_redirecttoReferrer = false;
          mysql_select_db($database_dbname, $dbname);

          $LoginRS__query=sprintf("SELECT Username, Password FROM SGUsers WHERE Username=%s AND Password=%s",
            GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

          $LoginRS = mysql_query($LoginRS__query, $Newsograph) or die(mysql_error());
          $loginFoundUser = mysql_num_rows($LoginRS);
          if ($loginFoundUser) {
             $loginStrGroup = "";

            if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
            //declare two session variables and assign them
            $_SESSION['MM_Username'] = $loginUsername;
            $_SESSION['MM_UserGroup'] = $loginStrGroup;       

            if (isset($_SESSION['PrevUrl']) && false) {
              $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
            }
            header("Location: " . $MM_redirectLoginSucenter code here      if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>

userindex.php

<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    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($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>

非常感谢阅读。我花了很多年时间试图弄清楚它并没有想到Dreamweaver会让它如此混乱!感谢。

1 个答案:

答案 0 :(得分:0)

这里有两个可能的拼写错误。你有UsernmaeBox而不是UsernameBox。除非你打算这样做。

if (isset($_POST['UsernmaeBox'])) {
      $loginUsername=$_POST['UsernmaeBox'];