|
19 | 19 |
|
20 | 20 | header('Pragma: no-cache');
|
21 | 21 |
|
22 |
| -$server = 'mongodb://localhost:27017'; |
| 22 | +$server = array( |
| 23 | + 'mongodb://localhost:27017', |
| 24 | +// 'mongodb://example.org:27017', |
| 25 | +); |
| 26 | + |
23 | 27 | $options = array(
|
24 | 28 | 'connect' => true
|
25 | 29 | );
|
|
30 | 34 | }
|
31 | 35 | try
|
32 | 36 | {
|
33 |
| - $mongo = new Mongo($server, $options); |
| 37 | + $mongo = new Mongo(getServer($server), $options); |
34 | 38 | }
|
35 | 39 | catch (MongoConnectionException $ex)
|
36 | 40 | {
|
37 | 41 | error_log($ex->getMessage());
|
38 | 42 | die("Failed to connect to MongoDB");
|
39 | 43 | }
|
40 | 44 |
|
| 45 | + |
| 46 | +/** |
| 47 | + * Get the current MongoDB server. |
| 48 | + * |
| 49 | + * @param mixed $server |
| 50 | + * @return string $server |
| 51 | + */ |
| 52 | +function getServer($server) |
| 53 | +{ |
| 54 | + if (is_array($server)) { |
| 55 | + return (isset($_COOKIE['mongo_server']) && isset($server[$_COOKIE['mongo_server']])) ? $server[$_COOKIE['mongo_server']] : $server[0]; |
| 56 | + } else { |
| 57 | + return $server; |
| 58 | + } |
| 59 | +} |
| 60 | + |
41 | 61 | /**
|
42 | 62 | * Render a document preview for the black code box with referenced
|
43 | 63 | * linked to the collection and id for that database reference.
|
@@ -450,7 +470,22 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
|
450 | 470 | <body>
|
451 | 471 |
|
452 | 472 | <div id="content">
|
453 |
| - <h1>PHP MongoDB Admin - <?php echo $server ?></h1> |
| 473 | + <h1> |
| 474 | + PHP MongoDB Admin - |
| 475 | + <?php if (is_array($server)): ?> |
| 476 | + <?php if (count($server) > 1): ?> |
| 477 | + <select id="server" onChange="document.cookie='mongo_server='+this[this.selectedIndex].value;document.location.reload();return false;"> |
| 478 | + <?php foreach ($server as $key => $s): ?> |
| 479 | + <option value="<?php echo $key ?>"<?php if (isset($_COOKIE['mongo_server']) && $_COOKIE['mongo_server'] == $key): ?> selected="selected"<?php endif; ?>><?php echo $s ?></option> |
| 480 | + <?php endforeach; ?> |
| 481 | + </select> |
| 482 | + <?php else: ?> |
| 483 | + <?php echo $server[0] ?> |
| 484 | + <?php endif; ?> |
| 485 | + <?php else: ?> |
| 486 | + <?php echo $server ?> |
| 487 | + <?php endif; ?> |
| 488 | + </h1> |
454 | 489 | <?php if (isset($_REQUEST['error'])): ?>
|
455 | 490 | <div class="error">
|
456 | 491 | <?php echo $_REQUEST['error'] ?>
|
|
0 commit comments