我正在尝试将 php 会话从一个页面传递到下一个页面。但是,当我加载第二页时,url 会发生变化,但会重新加载第一页。第 2 页中的任何内容都没有出现。我觉得是 isset 线搞砸了,但我可能错了。任何关于我可能会出错的想法将不胜感激。
第 0 页 html:
<div id="login">
<p>Username:
<input type="text" id="loginName" Required>
</p>
<p>Password:
<input type="password" id="loginPass" Required>
</p>
<span id="loginError">Please enter a username AND password</span>
第 0 页 jquery(这使用重定向插件):
$("#login").dialog({
modal: true,
buttons: {
Login: function(){
var userName = $("#loginName").val();
var userPass = $("#loginPass").val();
var request1 = $.ajax({
url: "indexDb.php",
async: true,
type: "POST",
data:{uName:userName, uPass:userPass, func:1},
dataType: "html"
}).success(function(data){
if(data == "Password Not Found"){
//alert(data);
$("#loginError").text("The password you entered was incorrect");
$("#loginError").show();
}
else if(data == "Name Not Found"){
$("#loginError").text("The username you entered was not found");
$("#loginError").show();
}
else{
uid = data;
$.ajax({
url: "home.php",
type: "POST",
data: {uName:uid},
datatype: "text"
}).success(function(data){
alert("user:" + data);
$().redirect('home.php', {'uName': data});
});
}
})//end success
} //end of login button
} //end of buttons
}); //end of dialog
第 1 页:
<?php
session_start();
if(isset($_POST['uName'])){
$_SESSION['currentID'] = $_POST['uName'];
$curUser = $_POST['uName'];
}
?>
<html>
<a href="page2.php">page 2</a>
</html>
第2页:
<?php
session_start();
echo $_SESSION['currentID']."hi";
?>