2 回答
TA贡献1812条经验 获得超5个赞
不安全,但把:
<?php
$uname=$_POST['uname'];
$password=$_POST['password'];
session_start();
$con=mysqli_connect("localhost","root","g7trj98o6fyr5","login");//mysqli("localhost","username of database","password of database","database name")
$result=mysqli_query($con,"SELECT * FROM `login_info` WHERE `uname`='$uname' && `password`='$password'");
$count=mysqli_num_rows($result);
if($count==1)
{
echo "Login success";
$_SESSION['log']=1;
$_SESSION['uname'] = $_POST['uname'];
header("refresh:2;url=welcome.php");
}
else
{
echo "please fill proper details";
header("refresh:2;url=index.php");
}
?>
然后检查:
if($logedInUsername == $_SESSION['uname'])
...
您还需要在welcome.php 中将$logedInUsername 设置为$row['uname'] 或检查
if($row['uname'] == $_SESSION['uname'])
TA贡献1829条经验 获得超9个赞
登录成功后在 login.php 中执行这个 $_SESSION['uname'] = $_POST['uname'];
在welcome.php 中执行这个 $logedInUsername = $_SESSION['uname'];
现在当前登录的用户名存储在$logedInUsernamewelcome.php中以供使用,这是因为SESSION是php中的全局变量,可以从任何地方访问。
while 循环和其中的 if 语句现在应如下所示:
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['uname'] . "</td>";
echo "<td>" . $row['clickrate'] . "</td>";
if($row['uname'] == $logedInUsername)
echo "<td>" . $row['yourword'] . "<a href='edityourword.php?edit=$row[yourword]'> edit</a></td>";
else
echo "<td>" . $row['yourword'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
- 2 回答
- 0 关注
- 121 浏览
添加回答
举报