0

I'm tryng to migrate from a myswl login system to a xml login system to save some internal process.

I have been trying to log using a xml file which is generated dinamically from a php page, but It doesn't work. Could you please take a look to the next code?

Regards

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);

    $user_name = "";
    $pwd ="";
    $login = "";
    $pass="";



    if(isset($_POST['login'])){

    session_start();
        $user_name = $_POST['user_name'];
        $pwd = md5($_POST['password']);


        if (strlen($user_name || $pwd) < 1) { exit(header("Location:logon.php")); }

    $mydata = new SimpleXMLElement('http://192.168.246.12/loginProcess/all.php', 0, true);
    $login = "";
    $pass = "";

    $checking = $mydata->xpath('//resultado/registro[contains(username,"'.$user_name.'") and  contains(pwd,"'.$pwd.'")]'); 
    foreach($checking as $user) {
      echo "Uer: {$user->username} , {$user->pwd}";

       if(($_POST["user_name"] == $user->username) && ($user == $cliente->pwd)){
            //set logged in
            $_SESSION['logged_in'] = true;
            $_SESSION['user_name'] = $user->username;

            exit(header("Location: ./default.php"));
        }

        }
    }
    ?>

    <form method="post" action="">
            <p>Username <input type="text" id ="user_name" name="user_name" size="20" /></p>

            <p>Password <input type="password" id="password" name="password" size="20" /></p>

            <p><input type="submit" value="Login" name="login" /></p>
        </form>
Fran Rod
  • 586
  • 4
  • 14
  • 26
  • Please don't hold plain passwords in your file, this is leaving you wide open to future problems, Use `password_hash` and `password_verify` as in https://stackoverflow.com/questions/30279321/how-to-use-password-hash – Nigel Ren Aug 09 '17 at 06:32
  • Hi @NigelRen, i will take a look to this, thank you – Fran Rod Aug 09 '17 at 09:33

1 Answers1

0

I have already got it. The correct xpath sentence is this one:

$checking= $mydata->xpath('//resultado/registro[(username[contains(.,'.$user_name.')]) and (pwd[contains(.,'.$pwd.')])]');
Fran Rod
  • 586
  • 4
  • 14
  • 26