首页 > 代码库 > php单入口请求

php单入口请求

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单入口请求