首页 > 代码库 > 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单入口请求
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。