Created
February 14, 2013 02:56
-
-
Save lankz/4950252 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$xml = <<<XML | |
<users> | |
<user> | |
<name>tim</name> | |
<email>[email protected]</email> | |
<password>plainpasswordsarebad</password> | |
</user> | |
</users> | |
XML; | |
$doc = new SimpleXMLElement($xml); | |
// dynamically generate an xpath like /users/user[name="tim"] | |
$users = $doc->xpath('/users/user[name="' . $username . '"]'); | |
if (empty($users)) { | |
// no user exists with that username | |
} else { | |
$user = $users[0]; // if there's more than one element, you have duplicate users | |
if ($user->password == $password) { | |
// login success | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment