Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9288581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:56:45+00:00 2026-06-18T19:56:45+00:00

I have a xml(mydata.xml) file that stores login detail as follows <?xml version =

  • 0

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:&nbsp;&nbsp; <input type="password" name="admin_password" />
</br></br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<a href='logout.php'>Logout</a>";
}
else
{
header("Location:login.php");
}
echo "&nbsp;&nbsp;&nbsp;";

echo "</br></br></br>";

?>
</body>
</html>

any help would be appritiated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:56:46+00:00Added an answer on June 18, 2026 at 7:56 pm

    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:

    <?php session_start();
    //already logged in
    if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']==true){
        exit(header("Location: ./admin_panel.php"));
    }
    ?>
    <html>
    <head>
    <title>Administrator Login Page</title>
    <style type="text/css">
    @import "style.css";
    </style>
    </head>
    <body>
    <h1>Administrator Login Page</h1>
    
    <?php echo (isset($_SESSION['error'])?'<span style="color:red">'.$_SESSION['error'].'</span>':null);?>
    <div>
        <form action="admin_verify.php" method="post">
            <label for="admin_name">User Name:</label> <input type="text" name="admin_name" />
            </br>
            <label for="admin_password">Password:</label> <input type="password" name="admin_password" />
            </br>
            <input style="margin-left:30px" type="submit" value="Login"/>
            <input type="reset" value="Reset"/>
        </form>
    </div>
    
    </body>
    </html>
    <?php 
    //unset error as its only required once
    unset($_SESSION['error']);
    ?>
    

    admin_veryify

    <?php
    session_start();
    $mydata = simplexml_load_file("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"]) || empty($_POST["admin_password"]))
        {
            $_SESSION['error']='Please fill in both username and password';
            exit(header("Location:login.php"));
        }
    
    
        if(($_POST["admin_name"] == $login) && ($_POST["admin_password"] == $password)){
            //set logged in
            $_SESSION['logged_in'] = true;
            //unset password no need to include that
            unset($mydata->login_details[$i]->password);
    
            //json encode the user stuff from the xml
            $_SESSION['user_details'] = json_encode($mydata->login_details[$i]);
    
            //goto admin
            exit(header("Location: ./admin_panel.php"));
        }
    }
    
    //as we have exited for loop (and therefore not been directed) we have a invalid login
    $_SESSION['error']='Invalid username or password';
    exit(header("Location:login.php"));
    ?> 
    

    admin panel

    <?php
    session_start();
    //logout
    if(isset($_GET['logout'])){unset($_SESSION['logged_in']);session_destroy();}
    
    
    //check login
    if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']==true){
        //json decode user details from session into an array
        $user_details = json_decode($_SESSION['user_details'],true);
    
        //debug your values
        echo '<pre>'.print_r($user_details,true).'</pre>';
        /*
        Array
        (
            [unique_ref] => 1-61
            [login_name] => tomme
            [login] => me
            [file1] => Test
            [file2] => Array
                (
                )
    
            [file3] => Array
                (
                )
    
            [file4] => Array
                (
                )
    
        )
        */
    
        echo '<a href="?logout">logout</a>';
    }else{
        exit(header("Location: ./login.php"));
    }
    ?> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to parse an XML document that looks like this: <?xml version=1.0 encoding=UTF-8
Let's say I have an existing trivial XML file named 'MyData.xml' that contains the
I have an XML file that I want to query with LINQ. I want
I have the following XML from a .NET web service: <?xml version=1.0 encoding=utf-8?> <DataSet>
I have an xml file that contains a list of items i can deserialize
I have some problems in writing down the schema of my XML file, that
I have an XML file that I deserialize into a class object. This class
I have a basic XML file that I load in my PHP using $xml
I have an XML file that looks like this <comments> <text> <![CDATA[ <!--cached-Tue, 02
I have xml file with such structure: ... <outer> ... <inner/> ... </outer> ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.