我正在使用php pdo,而且每件事都在工作而不是会话变量。我将表单变量通过ajax传递到另一个页面,编码是ajax
$.ajax({
url:"loginform.php",
method:"POST",
data:{recaptcha: grecaptcha.getResponse(), email:email, password:password},
success: function(data){
if(data == "notok"){
grecaptcha.reset();
errbox = $("#robotError");
errcontent = "please verify you are not robot";
showerror(errbox, errcontent);
}
}
});
并在loginform.php中使用此编码
$email = test_input($_POST["email"]);
$userPassword = test_input($_POST["password"]);
try {
$conn = new PDO("mysql:host=$servername;dbname=variablename", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "select email from table where email=?";
$statement = $conn->prepare($query);
$statement->execute(array($email));
$count = $statement->rowCount();
if($count == 1){
$query = "select password from table where email=?";
$statement = $conn->prepare($query);
$statement->execute(array($email));
$dbpassword = $statement->fetch(PDO::FETCH_ASSOC);
if($dbpassword['password'] == $userPassword){
$query = "SELECT firstName, lastName FROM table WHERE email=?";
$statement = $conn->prepare($query);
$statement->execute(array($email));
$dbFnandLn = $statement->fetch(PDO::FETCH_ASSOC);
$_SESSION['userfn'] = $dbFnandLn['firstName'];
$_SESSION['userln'] = $dbFnandLn['lastName'];
$_SESSION["loggedin"] = true;
echo "oldRegistered";
}
if($dbpassword['password'] != $userPassword){
echo "wrongpw";
}
$conn = null;
exit;
}
if($count < 1){
$_SESSION['userstatus'] = "needtoregistered";
echo "newRegistered";
$conn = null;
exit;
}
}
我的 $ _ SESSION [“loggedin”] 工作正常甚至一切都很好但是当我尝试显示名字和姓氏的会话变量时它没有出现,这里是编码< / p>
<section class="page-header page-header-light page-header-more-padding">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>User Home Page</h1>
<ul class="breadcrumb breadcrumb-valign-mid">
<li><a href="http://dineandparty.com">Home</a></li>
<li class="active">User: <?php $_SESSION['userfn']." ".$_SESSION['userln'] ?></li>
</ul>
</div>
</div>
</div>
</section>
我已经检查了我的表列名称,我使用完全相同的列名称,如
$ dbFnandLn [ '的firstName'];和$ dbFnandLn ['lastName'];
我也有session_start();在我的页面顶部。
有人可以帮助我
由于
答案 0 :(得分:1)
您没有指定echo
语句来显示会话数据
<?php echo $_SESSION['userfn']." ".$_SESSION['userln'] ?>