这是cus_login.php
:
<form method="post" action="cus_login.php">
<h2>LOG-IN</h2> <hr>
<div id="message" > <?php if ($msg != "") echo $msg ?></div>
<div class="form-group">
<input class="form-control" name="email_add" type="email" placeholder="Email...">
</div>
<div class="form-group">
<input class="form-control" name="password" type="password" placeholder="Password...">
</div>
<input class="btn btn-success" type="submit" name="submit" value="LOG IN">
</form>
此操作位于此文件上方,如下所示:
<?php include 'includes/config.php';
session_start();
if (isset($_POST['submit'])) {
$email_add = $con->real_escape_string($_POST['email_add']);
$password = $con->real_escape_string($_POST['password']);
if ($email_add == "" || $password == "")
$msg = "Empty Fields! Type in your Email address and Password";
else {
$sql = $con->query("SELECT * FROM tbl_customers WHERE email_add='$email_add'");
if ($sql->num_rows > 0) {
$data = $sql->fetch_array();
if (password_verify($password, $data['password'])) {
if ($data['confirm'] == 0)
$msg = "Please verify your email! Before logging in";
else {
session_start();
$_SESSION['id'] = $row['id'];
header("location: cus_prof.php");
}
} else
$msg = "Wrong Password! Please enter again.";
} else {
$msg = "Wrong Email Address! Please enter again";
}
} }?>
如何根据电子邮件或ID向其他页面或文件显示客户信息...如个人资料信息页面?
答案 0 :(得分:0)
<?php
session_start();
include 'includes/config.php';
/*note in your config.php must have the session_start(); function as the first line just after
opening php tag else session will not start and Your session variable will not be available */
$msg="";
if (isset($_POST['submit'])) {
$email_add = $con->real_escape_string($_POST['email_add']);
$password = $con->real_escape_string($_POST['password']);
if ($email_add == "" || $password == "")
$msg = "Empty Fields! Type in your Email address and Password";
else {
$sql = $con->query("SELECT * FROM tbl_customers WHERE email_add='$email_add'");
if ($sql->num_rows > 0) {
$data = $sql->fetch_array();
if (password_verify($password, $data['password'])) {
if ($data['confirm'] == 0)
$msg = "Please verify your email! Before logging in";
else {
// session_start(); this must be call in the first line of code before any other code
$_SESSION['id'] = $row['id'];
//here you can just add the data variable to the session`enter code here`
//$_SESSION['data'] = $data;
header("location: cus_prof.php");
}
} else
$msg = "Wrong Password! Please enter again.";
} else {
$msg = "Wrong Email Address! Please enter again";
}
}
}?>
// then in your cus_prof.php file
<?php
include 'includes/config.php';
$id =$_SESSION['id'];
$sql = $con->query("SELECT * FROM tbl_customers WHERE id='$id'");
if ($sql->num_rows > 0) {
$data = $sql->fetch_array();
//do whatever you want with the data in the $data array
}
?>
我刚刚将数据变量添加到会话中,您可以通过会话变量在任何位置访问数据变量中的任何内容。