-
-
Notifications
You must be signed in to change notification settings - Fork 627
Expand file tree
/
Copy pathuserdata.php
More file actions
50 lines (42 loc) · 1.34 KB
/
userdata.php
File metadata and controls
50 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<title>User Profile Lookup</title>
</head>
<body>
<?php
if (isset($_GET['usersearch']) && !empty($_GET['usersearch'])) {
try {
$result = "";
$conn = new MongoClient('mongodb://127.0.0.1');
$db = $conn->appUserData;
$collection = $db->users;
$search = $_GET['usersearch'];
$js = "function () { var query = '". $usersearch . "'; return this.username == query;}";
print $js;
print '<br/>';
$cursor = $collection->find(array('$where' => $js));
echo $cursor->count() . ' user found. <br/>';
foreach ($cursor as $obj) {
echo 'Name: ' . $obj['name'] . '<br/>';
echo 'Username: ' . $obj['username'] . '<br/>';
echo 'Email: ' . $obj['email'] . '<br/>';
echo '<br/>';
}
$conn->close();
} catch (MongoConnectionException $e) {
die('Error connecting to MongoDB server : ' . $e->getMessage());
} catch (MongoException $e) {
die('Error: ' . $e->getMessage());
}
}
?>
<b>Enter your username:</b><br>
<form method="get" id="usersearch">
<p>Search <input type="text" name="usersearch" id="usersearch" /> <input type="submit" name="submitbutton" value="Submit" /></p>
</form>
<div id="results">
<?php echo $result; ?>
</div>
</body>
</html>