我将会话变量的值设置在一个文件中。 然后我以嵌套的方式使用了两个文件来执行任务。 然后内部文件将调用一个新文件,这是一个正常的php文件。 现在,在所有这三个文件(两个嵌套文件和一个新文件)中,Session变量均未显示正确的值。 我的意思是它的值没有设置。 我在每个文件的开头使用session_start()。 包括那些嵌套文件。 我是php的新手,我想知道它的问题是什么。
这些函数将调用ajax.php
function change_subcatagory()
{
var xhttp;
var val=document.getElementById('subcat').value;
if (val.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
document.getElementById("question").innerHTML=this.responseText;
};
xhttp.open("GET", "ajax2.php?subcatagory="+val, true);
xhttp.send();
}
function change_catagory(){
var xhttp;
var val=document.getElementById('cat').value;
if (val.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
document.getElementById("sub").innerHTML = this.responseText;
};
xhttp.open("GET", "ajax.php?catagory="+val, true);
xhttp.send();
}
function signout()
{
session_destroy();
?>
var mywindow = window.open("Login.php",'_self');
}
ajax.php
session_start();
$hostname="localhost";
$username="root";
$password="";
$databaseName="project";
$connect = mysqli_connect($hostname,$username,$password,$databaseName);
$catagory = $_GET["catagory"];
if($catagory!='catagory'){
$sql = "SELECT * FROM sub_catagory WHERE CID=$catagory";
$res = $connect->query($sql);
if($res){
echo '
style="top:10px; border-radius:16px; width:300px; height:30px">';
while($row = $res->fetch_assoc()){
echo ''; echo $row["sub_cname"];
echo '';
}
echo '
';
}
else
echo mysqli_error($connect);
}
?>
它将调用ajax2.php
session_start();
$hostname="localhost";
$username="root";
$password="";
$databaseName="project";
$connect = mysqli_connect($hostname,$username,$password,$databaseName);
$subcatagory = isset($_GET['subcatagory']) ? $_GET['subcatagory'] : '';
$_SESSION["subcatagory"]=$subcatagory;
?>