intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Secure PHP Development- P25

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:5

56
lượt xem
4
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Secure PHP Development- P25: Welcome to Secure PHP Development: Building 50 Practical Applications. PHP has come a long way since its first incarnation as a Perl script. Now PHP is a powerful Web scripting language with object-oriented programming support. Slowly but steadily it has entered the non-Web scripting arena often reserved for Perl and other shell scripting languages. Arguably, PHP is one of the most popular Web platforms.

Chủ đề:
Lưu

Nội dung Text: Secure PHP Development- P25

  1. 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 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
  2. 92 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)); }
  3. 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; } Continued
  4. 94 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; }
  5. 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(‘SERVER_PORT’); if ($port == 80) { $port = null; } else { $port = ‘:’ . $port; } $protocol = strtolower(substr($row_protocol,0, strpos($row_protocol,’/’))); Continued
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2