2

I read some manuals and looked on stackoverflow but still my code doesn't work.

I have this PHP code

if(!file_exists("entrant/".$lgn.".xml")){
        $myfile = fopen("entrant/".$lgn.".xml", "w") or die("Nebylo možné vytvořit soubor!");
        $txt = "<?xml version='1.0' encoding='UTF-8'?>"
            . "<root>"
            . "<pwd>$pwd</pwd>"
            . "<pointsXY></pointsXY>"
            . "<pointsSBIRANI></pointsSBIRANI>"
            . "<triedXY>0</triedXY>"
            . "<triedSBIRANI>0</triedSBIRANI>"
            . "</root>";
        fwrite($myfile, $txt);
        fclose($myfile);
        $_SESSION['usr'] = $_POST['usr-lgn'];
        header('Location: content/stats.php');
    } else {
       $xml=simplexml_load_file("entrant/".$lgn.".xml") or die("Nemůžu přečíst soubor");
       if($xml['pwd']  === $pwd) {
            $_SESSION['usr'] = $_POST['usr-lgn'];
            header('Location: content/stats.php');   
       } else {
           echo "<script>alert('Zadal/a jste špatné heslo! ');</script>";
       }
    }

Part that isn't working is

} else {
           $xml=simplexml_load_file("entrant/".$lgn.".xml") or die("Nemůžu přečíst soubor");
           if($xml['pwd'] === $pwd) {
                $_SESSION['usr'] = $_POST['usr-lgn'];
                header('Location: content/stats.php');   
           } else {
               echo "<script>alert('Zadal/a jste špatné heslo! ');</script>";
           }
        }

XML file that I have created

<?xml version='1.0' encoding='UTF-8'?><root><pwd>test</pwd><pointsXY></pointsXY><pointsSBIRANI></pointsSBIRANI><triedXY>0</triedXY><triedSBIRANI>0</triedSBIRANI></root>

So basically when user has file I am trying to get his password. But I cant get him it always echo that alert. I am from Czech so you may not understand it but I don't have nothing to do with it I suppose so :) Thanks for all help

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
Filip Bartoš
  • 301
  • 3
  • 16
  • `if(['root']['pwd'] === $pwd)`? what? – u_mulder Jan 24 '17 at 19:31
  • What are the values of `$xml['pwd']`, `$pwd`? Have you checked them? – u_mulder Jan 24 '17 at 19:33
  • Sorry my bad if($xml['pwd'] === $pwd) { is that code that isnt working – Filip Bartoš Jan 24 '17 at 19:33
  • 1
    Have you tried `==` instead of `===`? Especially in JS codebase that might be a tricky part and I believe it behaves (almost) the same for PHP. See [this answer](http://stackoverflow.com/a/80649/5994041). Also, echo the values somewhere (e.g. to html) to check if you aren't just checking for garbage. – Peter Badida Feb 20 '17 at 09:53

0 Answers0