Created
October 12, 2012 19:56
-
-
Save anonymous/3881162 to your computer and use it in GitHub Desktop.
index
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 | |
require_once "include/Session.php"; | |
$session = new Session(); | |
if (!isset($session->valid)) { // user hasn't validated | |
$target = $_SERVER['REQUEST_URI']; // where I'm trying to go | |
require_once "login.php"; // forward request to login.php | |
exit(); | |
} | |
require_once "include/menu.php"; | |
$params = (object) $_REQUEST; | |
print_r($params); | |
$choices->order = array_fill_keys($menu, ""); | |
//print_r($choices->order); | |
//print_r($prices); | |
//if the session gets seriously messed up, | |
//uncomment the following statement, run, and then re-comment | |
//$session->unsetAll(); | |
if(isset($params->add)){ | |
$pick = $_GET['order']; | |
$order = preg_replace("/[^A-z0-9\ -]/","",$_GET['order']); | |
$sum = 0; | |
$qty = 1; | |
$session->selections[$order] = 1; | |
$choices->order[$order] = "selected"; | |
} | |
else { | |
$session->selections = array(); | |
$price = ""; | |
$order = ""; | |
$sum = ""; | |
$pick = ""; | |
$num = ""; | |
} | |
$selections = $session->selections; | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Takeout Order</title> | |
<style type="text/css"> | |
body { | |
padding: 10px 20px; | |
} | |
form { | |
margin: 10px 0; | |
} | |
#logout { | |
position: absolute; | |
top: 10px; | |
right: 10px; | |
} | |
table { | |
width: 250px; | |
} | |
</style> | |
</head> | |
<body> | |
<form action=""> | |
<button type='submit'>Start Over</button> | |
</form> | |
<h2>Your Order</h2> | |
<form action="" method="get"> | |
items: | |
<select name="order"> | |
<?php foreach ($menu as $key => $value): ?> | |
<option <?php echo $choices->order[$key] ?>> <?php echo $key?></option> | |
<?php endforeach ?> | |
</select> | |
<input type="submit" name="add" value="Add" /> | |
</form> | |
<table> | |
<tr id = "category"> | |
<td><?php echo "Item" ?></td> | |
<td><?php echo "Price" ?></td> | |
<td><?php echo "#" ?></td> | |
</tr> | |
<?php foreach ($selections as $order => $value ): ?> | |
<?php $sum += ($menu[$order]); ?> | |
<tr> | |
<td><?php echo $order ?></td> | |
<td><?php echo ($menu[$order])?></td> | |
<td><?php echo (++$session->selections[$order]) ?></td> | |
</tr> | |
<?php endforeach ?> | |
<tr> | |
<td><?php echo "Total: "?></td> | |
<td><?php echo $sum ?></td> | |
</tr> | |
</table> | |
<form id="logout" action="logout.php"> | |
<input type="hidden" name="target" value="." /> | |
<input type="submit" value="logout" /> | |
</form> | |
</body> | |
</html> |
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 | |
session_start(); | |
define( "SECRET", "-set-this-to-make-sessions-secure-" ); | |
define( "HASH", md5(dirname(__FILE__) . SECRET) ); | |
define( "KEY", "sess_" . HASH ); | |
class Session { | |
public function __set($name,$value) { | |
$_SESSION[KEY][$name] = $value; | |
} | |
public function & __get($name) { | |
return $_SESSION[KEY][$name]; | |
} | |
public function __toString() { | |
return print_r($_SESSION[KEY],true); | |
} | |
public function __isset($name) { | |
return isset($_SESSION[KEY][$name]); | |
} | |
public function __unset($name) { | |
unset($_SESSION[KEY][$name]); | |
} | |
public function unsetAll() { | |
unset($_SESSION[KEY]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment