使用ajax和php登录页面并设置会话,但在服务器的另一个php页面上成功登录后,我无法获得会话的值 登录 会员登录 用户名 密码 /////////// $(文档).ready(函数(){ $(“#pwd”).focus(函数(){ $(“#errmsg”).html(“”); }); $(“#登录”)。单击(函数(){ 用户名=$(“#用户名”).val(); pwd=$(“#pwd”).val(); 如果(用户名=“”| | pwd=“”) { $(“#req”).html(“所有字段均为必填项”); } 否则{ $.ajax({ 类型:“POST”, url:“memlogprocess.php”, 数据:“username=“+username+”&pwd=“+pwd, 成功:函数(数据){ 如果(数据==“正常”){ window.location=“memberwelcome.php”; } 否则{ $(“#errmsg”).html(“用户名或密码不正确!!!!”); 美元(“#pwd”).val(“”); } } /*beforeSend:function() { $(“#msg”).css('display'、'inline'、'important'); $(“#msg”).html(“加载…”) }*/ }); 返回false; } }); });
///////////////使用ajax和php登录页面并设置会话,但在服务器的另一个php页面上成功登录后,我无法获得会话的值 登录 会员登录 用户名 密码 /////////// $(文档).ready(函数(){ $(“#pwd”).focus(函数(){ $(“#errmsg”).html(“”); }); $(“#登录”)。单击(函数(){ 用户名=$(“#用户名”).val(); pwd=$(“#pwd”).val(); 如果(用户名=“”| | pwd=“”) { $(“#req”).html(“所有字段均为必填项”); } 否则{ $.ajax({ 类型:“POST”, url:“memlogprocess.php”, 数据:“username=“+username+”&pwd=“+pwd, 成功:函数(数据){ 如果(数据==“正常”){ window.location=“memberwelcome.php”; } 否则{ $(“#errmsg”).html(“用户名或密码不正确!!!!”); 美元(“#pwd”).val(“”); } } /*beforeSend:function() { $(“#msg”).css('display'、'inline'、'important'); $(“#msg”).html(“加载…”) }*/ }); 返回false; } }); });,php,jquery,ajax,Php,Jquery,Ajax,/////////////// <!DOCTYPE html> <html> <head> <title>Login</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="../rnc
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../rncdemo/w3.css">
<script src="../rncdemo/jquery/jquery.min.js"></script>
</head>
<body>
<?php
include('menubar.php');
?>
<center>
<div class="w3-dark-grey" style="max-width:650px">
<header class="w3-padding-32 w3-teal"><h4>Member Login</h4></header>
<br><br>
<form name="loginform" method="post">
<div id="req"></div>
<table>
<tr>
<td><label><b>User Name</b></label></td>
<td><input class ="w3-input w3-border" type="text" id="username" name="username" required /></td>
</tr>
<td><label><b>Password</b></label></td>
<td><input class="w3-input w3-border" type="password" id="pwd" name="pwd" required/></td>
</tr>
<tr>
<td></td><td class="w3-center">
<br>
<tr>
<td></td>
<td>
<input class ="w3-btn w3-teal w3-hover-red" name="login" type="submit" id="login" value="Login">
<input class ="w3-btn w3-light-grey w3-hover-red" name="reset" type="reset" id="reset" value="Reset">
</td>
</tr>
</table>
<br><br>
<div id="errmsg"></div>
</form>
</div>
</center>
<script src="memlogin.js"></script>
</body>
</html>
///////////
$(document).ready(function(){
$("#pwd").focus(function(){
$("#errmsg").html('');
});
$("#login").click(function(){
username = $("#username").val();
pwd = $("#pwd").val();
if(username=='' || pwd =='')
{
$("#req").html("All fields are required");
}
else{
$.ajax({
type: "POST",
url: "memlogprocess.php",
data: "username="+username+"&pwd="+pwd,
success: function(data){
if(data=="ok") {
window.location="memberwelcome.php";
}
else{
$("#errmsg").html("username or password is incorrect !!!!");
$("#pwd").val('');
}
}
/*beforeSend:function()
{
$("#msg").css('display', 'inline', 'important');
$("#msg").html("<img src='images/ajax-loader.gif' /> Loading...")
}*/
});
return false;
}
});
});
您需要在所有页面中启动会话
<?php
echo $_SESSION['memusername'];
?>
注意:-在php标记后面的页面顶部启动会话上面的代码是正确的。如果我们遇到这种问题,我们需要更改文件名。在服务器上,如果我们多次编辑单个文件,可能会出现这种错误。因此,我们需要更改文件名并编写相同的代码。插入查询在哪里??您无法使用$_session[“”]从数据库访问,您需要使用$row[“”]获取数据。amit sinha您尝试过我所述的吗?@amit您尝试过吗..正如我所说,不使用$row[“”]无法获取数据库数据@amit你还需要帮助吗?为什么我需要插入查询??目标是只从用户处获取用户名和密码,并检查它们是否成功设置会话,然后转到欢迎页面并打印会话值…这没有用。我不理解为什么会话值没有打印在最后(欢迎页面)上.某些浏览器(如chrome)在尝试2次或多次后显示该值,但某些浏览器(如opera mini)在会话成功设置时从不显示该值。
<?php
echo $_SESSION['memusername'];
?>
<?php session_start();?>