我创建了一个登录脚本,但即使我登录了不同的帐户,它也会将我指向同一个帐户。除了较低的密码安全性(这不是我目前关心的问题),请帮我纠正这个脚本。
Student_login.php
<body onLoad="javascript:document.form1.learner_id.focus()">
<?php include 'Header.php';?>
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.php'><span>PNHS Home</span></a></li>
<li class='last'><span></span></li>
</ul>
</div>
<?php if(!empty($_GET['flag']) && $_GET['flag'] == "success"){?>
<div align="center" class="stylered">
Congratulations! You are successfully registered. You can use your Learner Id and Password to login your account.
</div>
<?php } ?>
<br>
<br>
<form name="form2" method="post" action="Student_login_handler.php" onSubmit="return validate();">
<tr>
<td colspan="4"><table width="30%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#666666" bgcolor="#CCCCCC">
<tr align="center" bgcolor="#999999">
<td colspan="2" bgcolor="#99CC33" class="styleblock">Learner Login Here</td>
</tr>
<tr bgcolor="#E1E1E1" class="stylesmall">
<td width="35%" align="left" class="stylesmall">Learner Id : </td>
<td width="65%" align="left"><input name="learner_id" type="text" id="learner_id" method="post"></td>
</tr>
<tr bgcolor="#E1E1E1" class="stylesmall">
<td align="left" class="stylesmall">Password:</td>
<td align="left"><input name="student_password" type="password" id="student_password" method="post"></td>
</tr>
<tr bgcolor="#E1E1E1">
<td colspan="2" align="center">
<?php if(!empty($_GET['flag']) && $_GET['flag'] == "invalid") { ?>
<span class="stylered">Invalid Learner Id or Password</span>
<?php }?>
</td>
Student_login_handler.php
$learner_id = mysqli_real_escape_string(htmlentities($_POST['learner_id']));
$student_password = mysqli_real_escape_string(htmlentities($_POST['student_password']));
$student_id = htmlentities($_GET['id'], ENT_QUOTES);
$student_id = htmlentities($_GET['id'], ENT_QUOTES);
$query = "SELECT student_id,last_login_date FROM student_information WHERE learner_id='$learner_id' and student_password='$student_password'";
$result = mysqli_query($link_id, $query);
if(mysqli_error() != null){
die(mysqli_error());
}
if($date = mysqli_fetch_array($result))
{
$lastdate = $date['last_login_date'];
$date2 = date("d-m-Y h:i A",strtotime($lastdate));
$_SESSION['user_id'] = $date['student_id'];
$_SESSION["lastlogin"] =$date2;
$_SESSION["type"] = "Student";
mysqli_query("UPDATE student_information SET last_login_date=now() where student_id='{$_SESSION['user_id']}'",$link_id);
if(mysqli_error() != null){
die(mysqli_error());
}
header("location: Student_Home.php?id={$_SESSION}");
die();
}
else
{
$flag = "invalid";
header("location:Student_login.php?flag=$flag");
die();
请建议我们做什么。
答案 0 :(得分:1)
不确定这是做什么的:
header("location: Student_Home.php?id={$_SESSION}");
$_SESSION
是一组值,那么甚至会输出什么呢?你的意思是重定向到用户的ID?:
header("location: Student_Home.php?id={$_SESSION['user_id']}");
请注意,此处还有许多其他问题:
$_GET
获取值?但是那时你似乎没有对这个价值做任何事情。虽然它在那里的事实让我怀疑在这个应用程序的某个地方,你信任用户输入,比如让用户指定他们的ID。你要确保不这样做。答案 1 :(得分:0)
更改此
header("location: Student_Home.php?id={$_SESSION}");
到这个
header("location: Student_Home.php?id={$_SESSION['user_id']}");
或者更好地使用
header("location: Student_Home.php");
你可以通过以下方式取出Student_Home.php的值:
session_start();
$id = $_SESSION['user_id'];