forked from maltzj/HackRU-2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfortuneFrontend.php
53 lines (45 loc) · 1.28 KB
/
fortuneFrontend.php
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
51
52
53
<?php
require 'configuration.php';
$mongo_db=$MONGO_URI;
$m= new Mongo($mongo_db);
$url = parse_url($mongo_db);
$db_name = preg_replace('/\/(.*)/', '$1', $url['path']);
// use the database we connected to
$db = $m->selectDB($db_name);
$collection = $db->selectCollection("Fortunes");
$results = $collection->find();
$all_fortunes = array();
/*while($results->hasNext())
{
array_push($all_fortunes, $results->next());
}*/
foreach($results as $doc)
{
if($doc["fortune"] != FALSE)
{
array_push($all_fortunes, $doc["fortune"]);
}
}
$fortune_to_get = rand(0, count($all_fortunes)-1);
$fortune = $all_fortunes[$fortune_to_get];
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<title>Unfortunate Cookie</title>
</head>
<body>
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<a class="brand">Unfortunate cookie</a>
</div>
</div>
<div class="container">
<div class="hero-unit">
<center><h2><span class="text-error"> <?php echo $fortune ?></span></h2></center>
<center><a href="http://jmaltz.vverma.net/ominousFortune/fortuneFrontend.php">
<button class="btn btn-success">That's weak sauce, I want more</button>
</a></center>
</div>
</div>
</body>