-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
42 lines (34 loc) · 1.01 KB
/
index.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
<?php
/**
* Main entry point for the demo shop.
*
* @copyright Copyright (c) 2014 Antecons
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
// config.php sets up everything.
require_once(dirname( __FILE__ ) . '/config.php');
// Initialize a cart if it does not exist already.
if (!isset($_COOKIE['cart'])) {
setcookie('cart', '{}', NULL, '/');
}
// Routing rules
$rules = array(
'product' => "/product(?<product_id>/[\w\d\-]+)?",
'about' => "/about",
'cart' => "/cart",
'home' => "/"
);
// Parse the URI
$uri = rtrim(dirname($_SERVER["SCRIPT_NAME"]), '/');
$uri = '/' . trim(str_replace($uri, '', $_SERVER['REQUEST_URI']), '/');
$uri = urldecode($uri);
// Find appropriate rewrite rule.
foreach ($rules as $action => $rule) {
if (preg_match( '~^'.$rule.'$~i', $uri, $params)) {
include(INCLUDE_PATH . $action . '.php');
// Exit to avoid the 404 message
exit();
}
}
// Nothing is found so return a 404.
show404();