PHP MySQL登录问题

I made a user portal and everything seems to work fine but with only one thing. Whenever I login using a different username and password, the name being displayed in the profile section remains the same even if I am already using different username.

Dashboard <small><?php echo $row_Recordset1['firstname']; ?> <?php echo $row_Recordset1['lastname']; ?> (<?php echo $row_Recordset1['username']; ?>)</small>

Please help. I tried putting it in '$_SESSION' but nothing works.

EDIT: (the full code)

<?php require_once('Connections/Authentication.php'); ?>
 <script type="text/javascript" src="crozlandinc/js/common.js"></script>
<script type="text/javascript" src="crozlandinc/js/drag.js"></script>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

mysql_select_db($database_Authentication, $Authentication);
$query_Recordset1 = "SELECT * FROM login";
$Recordset1 = mysql_query($query_Recordset1, $Authentication) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

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 = "login.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;
}
?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->

<!-- BEGIN HEAD -->
<head>
     <meta charset="UTF-8" />
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
     <!--[if IE]>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <![endif]-->
    <!-- GLOBAL STYLES -->
    <link rel="stylesheet" href="css/bootstrap.css" />
    <link rel="stylesheet" href="assets/css/main.css" />
    <link rel="stylesheet" href="assets/css/theme.css" />
    <link rel="stylesheet" href="assets/css/MoneAdmin.css" />
    <link rel="stylesheet" href="assets/plugins/Font-Awesome/css/font-awesome.css" />
     <!-- PAGE LEVEL STYLES -->
    <!-- END PAGE LEVEL  STYLES -->
     <!-- END PAGE LEVEL STYLES -->
   <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
</head>
    <!-- END HEAD -->

    <!-- BEGIN BODY -->
<body style="background-color:WHITE">
<div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                            Administrator Dashboard <small><?php echo $row_Recordset1['firstname']; ?> <?php echo $row_Recordset1['lastname']; ?> (<?php echo $row_Recordset1['username']; ?>)</small>
                        </h1>
                        <ol class="breadcrumb">
                            <li class="active">
                                <i class="fa fa-dashboard"></i> Dashboard
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->





      <!-- PAGE LEVEL SCRIPTS -->
      <script src="assets/plugins/jquery-2.0.3.min.js"></script>
      <script src="assets/plugins/bootstrap/js/bootstrap.js"></script>
   <script src="assets/js/login.js"></script>
      <!--END PAGE LEVEL SCRIPTS -->
 <script src="assets/plugins/validationengine/js/jquery.validationEngine.js"></script>
    <script src="assets/plugins/validationengine/js/languages/jquery.validationEngine-en.js"></script>
    <script src="assets/plugins/jquery-validation-1.11.1/dist/jquery.validate.min.js"></script>
    <script src="assets/js/validationInit.js"></script>
    <script>
        $(function () { formValidation(); });
        </script>
</body>
    <!-- END BODY -->
</html>
<?php
mysql_free_result($Recordset1);
?>
duaiwo9093
duaiwo9093 实际上,如果通过身份验证部分,那部分必须正常工作。为什么不直接将需要打印的变量添加到login.php文件中的会话中。然后做echo$_SESSION['first_name'];在HTML中。
接近 5 年之前 回复
doumi5223
doumi5223 首先我建议做一个var_dump($_SESSION);在html中检查login.php页面是否实际设置了正确的会话变量。
接近 5 年之前 回复
dongxixiu9134
dongxixiu9134 你有什么建议@Phil_1984_?
接近 5 年之前 回复
douba1498
douba1498 那很好笑。但我再次使用了Dreamweaver自动提供的代码。无论如何我们至少会在改变一切之前给它一个修复试验,还是我应该放弃?
接近 5 年之前 回复
dongwubao4785
dongwubao4785 看起来你只是在执行SELECT*FROM登录获取第一行并打印名称。当然,每次都会显示同样的事情。
接近 5 年之前 回复
duai1683
duai1683 哇,GetSQLValueString很糟糕。我以为我已经看过最后一种编码了。说真的,至少要10岁。
接近 5 年之前 回复
dtujfmfs06058
dtujfmfs06058 然后,您需要找到一个新的托管服务提供商。至少转移到mysqli。这个东西已经被推荐了4年了。
接近 5 年之前 回复
drk7700
drk7700 我害怕使用PDO,因为我的托管不支持。我希望有人能给我一个更具体的答案:(
接近 5 年之前 回复
douan4106
douan4106 你应该看看这个:stackoverflow.com/questions/12859942/...
接近 5 年之前 回复
donglvmang8638
donglvmang8638 好的,我会努力回答你
接近 5 年之前 回复
dsaj20411
dsaj20411 我已经发布了完整的代码。
接近 5 年之前 回复
duanmei1350
duanmei1350 为了你的视觉效果。请访问crozland.com/admin然后尝试使用以下命令登录:用户名1:nmal6193密码1:密码||用户名2:mod:nmal6193密码2:密码。尝试使用两者登录,它们将在仪表板中返回相同的名称和用户详细信息。
接近 5 年之前 回复
dtdsbakn210537
dtdsbakn210537 $row_Recordset1是使用Dreameaver创建的记录集。我想在登录时显示特定用户的详细信息,但如果我使用不同的用户名,则显示的详细信息是相同的。
接近 5 年之前 回复
douweng5420
douweng5420 我用Dreamweaver创建了代码。@Stah的名字应该在Recordset1里面。
接近 5 年之前 回复
dtotuki47568
dtotuki47568 警告:编写自己的访问控制层并不容易,并且有很多机会严重错误。当Laravel这样的现代开发框架内置强大的身份验证系统时,请不要编写自己的身份验证系统。
接近 5 年之前 回复
douren8379
douren8379 你能发布完整的代码吗?
接近 5 年之前 回复
dsm13698679318
dsm13698679318 您可能还想在检查登录详细信息的位置添加代码-$row_Recordset1来自哪里?
接近 5 年之前 回复
doubu5154
doubu5154 我真的不明白。是在会话中显示的名称还是在$row_Recordset1中?
接近 5 年之前 回复

2个回答



首先你最不使用MySQL,因为它将在php-7中删除,不会再使用了</ p>

尝试编辑你的代码并将其全部转换为MySQLi它非常简单</ p>

第二,我认为你最常使用 session_destroy()</ code>如果你使用< code> unset($ _ SESSION ['name'])</ code> </ p>
</ div>

展开原文

原文

first you most not use the MySQL because it will be deleted in php-7 and will not using any more

try to edit your code and convert it all to MySQLi its really simple

second i think u most use session_destroy() if u r using unset($_SESSION['name'])

dszpyf4859
dszpyf4859 这不是问题的答案。 获得足够的声誉后,您就可以发表评论。
接近 5 年之前 回复
dongmian5325
dongmian5325 事实并非如此。 无论是否是我的第一次登录,它仍然会显示相同的用户信息(这是sql btw中的第一项)。 我是通过Dreamweaver创建的,所以将所有内容转换为mysqli会很痛苦。
接近 5 年之前 回复



似乎 row_Recordset1 </ code>总是填充查询结果的第一行。 我认为你需要扩展你的查询只选择1条记录,作为登录用户的记录。</ p>

  //你在这里选择所有行
$ query_Recordset1 =“ SELECT * FROM login“;
$ Recordset1 = mysql_query($ query_Recordset1,$ Authentication)或die(mysql_error());
//您将结果集的第一行放在此记录集中,
//无论哪个 用户已登录
$ row_Recordset1 = mysql_fetch_assoc($ Recordset1);
</ code> </ pre>
</ div>

展开原文

原文

It seems like row_Recordset1 is always populated with the first row from the query result. I think you need to extend your query to select only 1 record, being the record of the logged in user.

// You select all rows here
$query_Recordset1 = "SELECT * FROM login";
$Recordset1 = mysql_query($query_Recordset1, $Authentication) or die(mysql_error());
// You put the first row of the resultset in this recordset,
// no matter which user is logged in
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐