Skip to content

Instantly share code, notes, and snippets.

@lankz
Created February 14, 2013 02:56
Show Gist options
  • Save lankz/4950252 to your computer and use it in GitHub Desktop.
Save lankz/4950252 to your computer and use it in GitHub Desktop.
<?php
$xml = <<<XML
<users>
<user>
<name>tim</name>
<email>tim@timland.com</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