1. Trang chủ
  2. » Công Nghệ Thông Tin

Secure PHP Development- P25 pps

5 171 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 82,49 KB

Nội dung

In this example, the first two debug messages (“Name = $name” and “Email = $email” ) will be printed after the “This will print before debug messages. \n\n” message. In the next section, we look at how we can incorporate all of these classes to cre- ate an abstract PHP application class. Creating an Abstract Application Class The code in Listing 4-4 uses class.DBI.php, class.ErrorHandler.php, and class.Debugger.php to create an abstract PHP application class. Listing 4-4: class.PHPApplication.php <?php /* * * PHPApplication class * * @author <php@evoknow.com> * @access public * * Version 1.0.1 */ if (defined(“DEBUGGER_LOADED”) && ! empty($DEBUGGER_CLASS)) { include_once $DEBUGGER_CLASS; } //require_once ‘lib.session_handler.php’; class PHPApplication { function PHPApplication($param = null) { global $ON, $OFF, $TEMPLATE_DIR; Continued Chapter 4: Architecture of an Intranet Application 91 07 549669 ch04.qxd 4/4/03 9:24 AM Page 91 Listing 4-4 (Continued) global $MESSAGES, $DEFAULT_LANGUAGE, $REL_APP_PATH, $REL_TEMPLATE_DIR; // initialize application $this->app_name = $this->setDefault($param[‘app_name’], null); $this->app_version = $this->setDefault($param[‘app_version’], null); $this->app_type = $this->setDefault($param[‘app_type’], null); $this->app_db_url = $this->setDefault($param[‘app_db_url’], null); $this->debug_mode= $this->setDefault($param[‘app_debugger’], null); $this->auto_connect = $this->setDefault($param[‘app_auto_connect’], TRUE); $this->auto_chk_session = $this- >setDefault($param[‘app_auto_chk_session’], TRUE); $this->auto_authorize = $this- >setDefault($param[‘app_auto_authorize’], TRUE); $this->session_ok = $this- >setDefault($param[‘app_auto_authorize’], FALSE); $this->error = array(); $this->authorized= FALSE; $this->language = $DEFAULT_LANGUAGE; $this->base_url = sprintf(“%s%s”, $this->get_server(), $REL_TEMPLATE_DIR); $this->app_path = $REL_APP_PATH; $this->template_dir = $TEMPLATE_DIR; $this->messages = $MESSAGES; // If debuggger is ON then create a debugger object if (defined(“DEBUGGER_LOADED”) && $this->debug_mode == $ON) { if (empty($param[‘debug_color’])) { $param[‘debug_color’] = ‘red’; } $this->debugger = new Debugger(array(‘color’ => $param[‘debug_color’], ‘prefix’ => $this->app_name, ‘buffer’ => $OFF)); } 92 Part II: Developing Intranet Solutions 07 549669 ch04.qxd 4/4/03 9:24 AM Page 92 // load error handler $this->has_error = null; $this->set_error_handler(); // start session if (strstr($this->get_type(), ‘WEB’)) { session_start(); $this->user_id = (! empty($_SESSION[“SESSION_USER_ID”])) ? $_SESSION[“SESSION_USER_ID”] : null; $this->user_name = (! empty($_SESSION[“SESSION_USERNAME”])) ? $_SESSION[“SESSION_USERNAME”]: null;; $this->user_email = (! empty($_SESSION[“SESSION_USERNAME”])) ? $_SESSION[“SESSION_USERNAME”]: null;; $this->set_url(); if ($this->auto_chk_session) $this->check_session(); if (! empty($this->app_db_url) && $this->auto_connect && ! $this- >connect()) { $this->alert(‘APP_FAILED’); } if ($this->auto_authorize && ! $this->authorize()) { $this->alert(‘UNAUTHORIZED_ACCESS’); } } } function getEMAIL() { return $this->user_email; } Continued Chapter 4: Architecture of an Intranet Application 93 07 549669 ch04.qxd 4/4/03 9:24 AM Page 93 Listing 4-4 (Continued) function getNAME() { list($name, $host) = explode(‘’, $this->getEMAIL()); return ucwords($name); } function check_session() { if ($this->session_ok == TRUE) { return TRUE; } if (!empty($this->user_name)) { $this->session_ok = TRUE; } else { $this->session_ok = FALSE; $this->reauthenticate(); } return $this->session_ok; } function reauthenticate() { global $AUTHENTICATION_URL; header(“Location: $AUTHENTICATION_URL?url=$this->self_url”); } function getBaseURL() { return $this->base_url; } 94 Part II: Developing Intranet Solutions 07 549669 ch04.qxd 4/4/03 9:24 AM Page 94 function get_server() { $this->set_url(); return $this->server; } function getAppPath() { return $this->app_path; } function getFQAP() { // get fully qualified application path return sprintf(“%s%s”,$this->server, $this->app_path); } function getFQAN($thisApp = null) { return sprintf(“%s/%s”, $this->getFQAP(), $thisApp); } function getTemplateDir() { return $this->template_dir; } function set_url() { $row_protocol = $this->getEnvironment(‘SERVER_PROTOCOL’); $port = $this->getEnvironment(‘SERVER_PORT’); if ($port == 80) { $port = null; } else { $port = ‘:’ . $port; } $protocol = strtolower(substr($row_protocol,0, strpos($row_protocol,’/’))); Continued Chapter 4: Architecture of an Intranet Application 95 07 549669 ch04.qxd 4/4/03 9:24 AM Page 95 . abstract PHP application class. Creating an Abstract Application Class The code in Listing 4-4 uses class.DBI .php, class.ErrorHandler .php, and class.Debugger .php to create an abstract PHP application. create an abstract PHP application class. Listing 4-4: class.PHPApplication .php < ?php /* * * PHPApplication class * * @author < ;php@ evoknow.com> * @access public * * Version 1.0.1 */ if. empty($DEBUGGER_CLASS)) { include_once $DEBUGGER_CLASS; } //require_once ‘lib.session_handler .php ; class PHPApplication { function PHPApplication($param = null) { global $ON, $OFF, $TEMPLATE_DIR; Continued Chapter

Ngày đăng: 07/07/2014, 07:20