我有一个客户表。每个客户都有一个特定的ID。 在我的项目(ecommerce website
)中,我想在成功登录时将用户的ID存储在$ _SESSION ['user_id']中。 我该怎么做?我需要添加什么? 这里是我的代码:使用php获取标识
<?php
// establishing the MySQLi connection
$con = mysqli_connect("localhost","root","","ecommerce");
// checking the user
if(isset($_POST['login'])){
$email = mysqli_real_escape_string($con,$_POST['c_email']);
$pass = mysqli_real_escape_string($con,$_POST['pass']);
$sel_user = "select * from customer where customer_email ='$email' AND customer_pass='$pass'";
$run_user = mysqli_query($con, $sel_user);
$check_user = mysqli_num_rows($run_user);
if($check_user>0){
$_SESSION['customer_email']=$email;
echo "<script>window.open('index.php','_self')</script>";
} else {
echo "<script>alert('Email or password is not correct, try again!')</script>";
}
}
?>
开始会话。 http://php.net/manual/en/function.session-start.php你也可以使用'header'而不是'echo“”'。 – chris85
呵呵,然后让userid对查询结果运行一个提取并将用户标识存储在会话变量中。 – chris85
你应该[hash](http://php.net/manual/en/faq.passwords.php )你的密码,并利用MySQLi的[准备语句](http://php.net/manual/en/mysqli.prepare.php)。 – Script47