I have a xml(mydata.xml) file that stores login detail as follows
<?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>
I have a login file to enter the details
<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>
I have also a admin_verify file
<?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";
?>
the problem is with the sessions in the admin_panel because I am trying to get $loginname from the xml file up to the admin_verify file it passes ‘tomme’ but the admin_panel file is where I am lost I am also tring to pass the details of ‘tomme’ in xml file to display the contents of file1 any ideas on how to achive this if I hard code $loginname to admin in all session page then it works fine but I would like to pass the information dynamically
the admin_panel is as follows
<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>
any help would be appritiated
First off its not a good idea to store plain text passwords in any file regardless. anyways
You can json_encode the simpleXML object and insert that into your session then pass the values to admin panel.
check out the edits of all 3 files, hope it helps.
Login:
admin_veryify
admin panel