我有一个存储登录详细信息的 xml(mydata.xml) 文件,如下所示
<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
<MYData>
<login_details>
<unique_ref>1-61</unique_ref>
<login_name>tomme</login_name>
<login>me</login>
<password>me</password>
<file1>Test</file1>
<file2/>
<file3/>
<file4/>
</login_details>
<login_details>
<unique_ref>1-61</unique_ref>
<login_name>tony</login_name>
<login>tony</login>
<password>tony</password>
<file1>Test1</file1>
<file2/>
<file3/>
<file4/>
</login_details>
</MYData>
我有一个登录文件来输入详细信息
<html>
<head>
<title>Administrator Login Page</title>
<style type="text/css">
@import "style.css";
</style>
</head>
<body>
<h1>Administrator Login Page</h1>
</br></br></br></br></br></br></br>
<form action="admin_verify.php" method="post">
User Name: <input type="text" name="admin_name" />
</br></br>
Password: <input type="password" name="admin_password" />
</br></br>
<input type="submit" value="Login"/>
<input type="reset" value="Reset"/>
</form>
</body>
</html>
我还有一个 admin_verify 文件
<?php
session_start();
$mydata = simplexml_load_file("xml/mydata.xml");
$login = "";
$password = "";
$loginname = "";
for($i = 0; $i < count($mydata); $i++){
$login = $mydata->login_details[$i]->login;
$password = $mydata->login_details[$i]->password;
$loginname = $mydata->login_details[$i]->login_name;
if(empty($_POST["admin_name"]))
{
header("Location:login.php");
return false;
}
if(empty($_POST["admin_password"]))
{
$this->HandleError("Password is empty!");
return false;
}
if(($_POST["admin_name"] == $login) && ($_POST["admin_password"] == $password)){
$_SESSION['name'] = "$loginname";
header("Location:admin_panel.php");
}
}
//as we have exited for loop (and therefore not been directed) we have a invalid login
echo "invalid username or password";
?>
问题在于 admin_panel 中的会话,因为我试图从 xml 文件获取 $loginname 到 admin_verify 文件,它传递了“tomme”,但 admin_panel 文件是我迷路的地方我也想传递“ tomme' 在 xml 文件中显示 file1 的内容 如果我在所有会话页面中将 $loginname 硬编码给管理员,那么它工作正常但我想动态传递信息 admin_panel 如下所示
<html>
<head>
<title>Administrator Panel</title>
<style type="text/css">
@import "style.css";
</style>
</head>
<body>
<h1>Administrator Panel</h1>
<?php
session_start();
$mydata = simplexml_load_file("xml/mydata.xml");
for ($i=0; $i < count($mydata);++$i)
$loginname = $mydata->login_details[$i]->login_name;
if($_SESSION['name']=="$loginname")
{
echo "Welcome ".$_SESSION['name'];
echo " ";
echo "<a href='logout.php'>Logout</a>";
}
else
{
header("Location:login.php");
}
echo " ";
echo "</br></br></br>";
?>
</body>
</html>
任何帮助都会得到满足