Danh mục

Secure PHP Development- P25

Số trang: 5      Loại file: pdf      Dung lượng: 82.49 KB      Lượt xem: 4      Lượt tải: 0    
Thư viện của tui

Phí tải xuống: 3,000 VND Tải xuống file đầy đủ (5 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Secure PHP Development- P25: Welcome to Secure PHP Development: Building 50 Practical Applications. PHPhas come a long way since its first incarnation as a Perl script. Now PHP is a powerfulWeb scripting language with object-oriented programming support. Slowlybut steadily it has entered the non-Web scripting arena often reserved for Perl andother shell scripting languages. Arguably, PHP is one of the most popular Web platforms.
Nội dung trích xuất từ tài liệu:
Secure PHP Development- P25 Chapter 4: Architecture of an Intranet Application 91 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 AbstractApplication ClassThe code in Listing 4-4 uses class.DBI.php, class.ErrorHandler.php, andclass.Debugger.php to create an abstract PHP application class.Listing 4-4: class.PHPApplication.php92 Part II: Developing Intranet Solutions 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)); } Chapter 4: Architecture of an Intranet Application 93 // 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; } Continued94 Part II: Developing Intranet Solutions 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; } Chapter 4: Architecture of an Intranet Application 95 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(‘S ...

Tài liệu được xem nhiều: