標籤:style blog os io ar 檔案 資料 art div
index.php:
<?phprequire_once ‘config.php‘;require_once DB_DIR . ‘db.php‘;//資料庫物件$DB = new MySQL();/** * 單入口Dispatcher處理 *///是否登陸//if ($_GET[‘action‘] != ‘login‘) {// if (empty($_SESSION[‘user‘])) {// return 0;// }//}$controller = !empty($_GET[‘controller‘]) ? $_GET[‘controller‘] : ‘index.php‘;$dir = CLASSES_DIR . ‘/‘ . $controller . ‘/‘ . $controller . ‘.php‘;if (is_file($dir) && !empty($_GET[‘controller‘])) { include_once $dir; $obj = new $_GET[‘controller‘](); $action = $_GET[‘action‘]; if (!empty($action)) { echo $obj->$action(); } //清除對象 unset($obj);} else { //未登陸或請求錯誤 echo 0;}$DB->CloseConnection();
config.php:
<?phperror_reporting(E_ERROR);session_start(); //開啟sessiondate_default_timezone_set(‘Asia/Shanghai‘); //時區設定/** * 檔案地址常量定義 */define(‘BASE_DIR‘, dirname(__FILE__)); //根目錄define(‘CLASSES_DIR‘, BASE_DIR . ‘/Classes/‘); //Classes目錄define(‘DB_DIR‘, CLASSES_DIR . ‘db/‘); //資料庫物件目錄define(‘TEST_DIR‘, CLASSES_DIR . ‘test/‘); //php測試類別
php單入口請求