因此,这里是我的网站登录页面的代码,我希望它在用户登录并将其存储在会话中时从数据库中拉出用户ID数据。我将在另一个页面中使用来从另一个表中提取值。从数据库中通过电子邮件将userId拉出并在会话中存储用户ID
<?php
session_start();
//Connect to DB
include_once 'db_connect.php';
// escape variables for security
$Email = mysqli_real_escape_string($mysqli, $_POST['email']);
$Password = mysqli_real_escape_string($mysqli, $_POST['password']);
//password hashing
$Password = hash("sha256", $Password);
$sqli="SELECT * FROM users WHERE Email='$Email' and Password='$Password'";
$result=mysqli_query($mysqli, $sqli);
//Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
// If result matched $Email and $Password, table row must be 1 row
if($count==1){
//redirect to file "menu.html"
header("location:menu.html");
}
//If all else fails they shall not pass!
else {
echo "Wrong Email or Password. YOU SHALL NOT PASS!";
}
?>
代码将从安全性得到改善,这是更多的获得功能工作版本,然后擦亮它 –
我没有看到一个问题? – Steve
问题是我如何获取用户标识,然后将其存储在会话数据中? –