Home Backend Development PHP Tutorial PHP整合你的站点入口_PHP

PHP整合你的站点入口_PHP

Jun 01, 2016 pm 12:30 PM
function Entrance Integrate document site website parse path

大家也许经常在网上看到这样的路径(http://www.aaa.com/aaa/bbb/aaa?id=5),让人不解,这样的网站的实现方式有几种可能性:
1、隐藏文件的扩展名,对这种做法的好处,众说纷纭,不过个人觉得没有必要;
2、用了网站的重定向规则,实现虚拟路径;
3、强制文件解析的方式,实现虚拟路径。
用第2\3种方法可以实现网站的统一接口,合理的整合网站,更好的体现网站的安全性和架构,用这两种方式的网站大多是使用"MVC"模式构建和实现的。

下面是一个例子
访问路径如下:

....../test/*******/Bad
....../test/*******/Good
(其中的"******"可以用任何字符串替换,"......."是你的web路径)


文件的目录结构如下
|--.htaccess
|-- test
|-- Application.php
|-- Controler/GoodControler.php
|-- Controler/BadControler.php


注意文件".htaccess",在windows下不能直接建立的,可以在命令行模式下建立.

文件0 (.htaccess) (这个文件是更改apache的配置方式用的)

forcetype application/x-httpd-php


文件1 (test.php)
/*-------------------------------------
* test.php
*
* 作为你的网站的入口的文件
* 用来初始化和入口
* 调用执行Controler的调用
*
-------------------------------------*/
require "Application.php";
$aa = new Application();
$aa->parse();
$aa->go();

?>


文件2 (GoodControler.php)
/*-------------------------------------
* GoodControler.php
*
* 用来控制 url=/test/Good 来的访问
*
-------------------------------------*/
class GoodControler{
/*
* 控制类的调用方法,唯一的报漏给外部的接口
*/
function control(){
echo "this is from GoodControler url=*********/test/Good";
}
}
?>


文件3 (BadControler.php)
/*-------------------------------------
* BadControler.php
*
* 用来控制 url=/test/Bad 来的访问
*
-------------------------------------*/
class BadControler{
/*
* 控制类的调用方法,唯一的报漏给外部的接口
*/
function control(){
echo "this is from GoodControler url=*********/test/Bad";
}
}
?>


文件4 (Application.php)
/*-------------------------------------
* Application.php
*
* 用来实现网站的统一入口,调用Controler类
*
-------------------------------------*/
class Application{
//用来记录所要进行的操作
var $action;
//controler文件的路径名
var $controlerFile;
//controler的类名
var $controlerClass;

function Application(){
}

function parse(){
$this->_parsePath();
$this->_getControlerFile();
$this->_getControlerClassname();
}
/*
* 解析当前的访问路径,得到要进行动作
*/
function _parsePath(){
list($path, $param) = explode("?", $_SERVER["REQUEST_URI"]);
$pos = strrpos($path, "/");
$this->action = substr($path, $pos 1);
}
/*
* 通过动作$action,解析得到该$action要用到的controler文件的路径
*/
function _getControlerFile(){
$this->controlerFile = "./Controler/".$this->action."Controler.php";
if(!file_exists($this->controlerFile))
die("Controler文件名(".$this->controlerFile.")解析错误");
require_once $this->controlerFile;
}
/*
* 通过动作$action,解析得到该$action要用到的controler类名
*/
function _getControlerClassname(){
$this->controlerClass = $this->action."Controler";
if(!class_exists($this->controlerClass))
die("Controler类名(".$this->controlerClass.")解析错误");
}
/*
* 调用controler,执行controler的动作
*/
function go(){
$c = new $this->controlerClass();
$c->control();
}
}
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to transfer files from Quark Cloud Disk to Baidu Cloud Disk? How to transfer files from Quark Cloud Disk to Baidu Cloud Disk? Mar 14, 2024 pm 02:07 PM

Quark Netdisk and Baidu Netdisk are currently the most commonly used Netdisk software for storing files. If you want to save the files in Quark Netdisk to Baidu Netdisk, how do you do it? In this issue, the editor has compiled the tutorial steps for transferring files from Quark Network Disk computer to Baidu Network Disk. Let’s take a look at how to operate it. How to save Quark network disk files to Baidu network disk? To transfer files from Quark Network Disk to Baidu Network Disk, you first need to download the required files from Quark Network Disk, then select the target folder in the Baidu Network Disk client and open it. Then, drag and drop the files downloaded from Quark Cloud Disk into the folder opened by the Baidu Cloud Disk client, or use the upload function to add the files to Baidu Cloud Disk. Make sure to check whether the file was successfully transferred in Baidu Cloud Disk after the upload is completed. That's it

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

How to add trusted sites in Google Chrome How to add trusted sites in Google Chrome Jul 19, 2024 pm 04:14 PM

How to add trusted sites in Google Chrome? Some users cannot browse the web normally because the page prompts that it is not secure when surfing the Internet. At this time, they can add the website as a trusted site, and we can access it normally and surf the Internet smoothly. The editor below will bring you the steps to add a trusted site in Google Chrome. The steps are simple and easy to operate, and even beginners can easily get started. Friends who need it can learn about it together. How to add a trusted site in Google Chrome: 1. Open Google Chrome and click the three dots in the upper right corner. Click [Settings]. Choose privacy settings and security. (As shown in the picture) 2. Click Website Settings at the bottom of the page. (As shown in the picture) 3. Click on the unsafe content at the bottom of the page. (As shown in the picture) 4. Click the Add button to the right of the Allow option. (As shown in the picture) 5. Lose

What is hiberfil.sys file? Can hiberfil.sys be deleted? What is hiberfil.sys file? Can hiberfil.sys be deleted? Mar 15, 2024 am 09:49 AM

Recently, many netizens have asked the editor, what is the file hiberfil.sys? Can hiberfil.sys take up a lot of C drive space and be deleted? The editor can tell you that the hiberfil.sys file can be deleted. Let’s take a look at the details below. hiberfil.sys is a hidden file in the Windows system and also a system hibernation file. It is usually stored in the root directory of the C drive, and its size is equivalent to the size of the system's installed memory. This file is used when the computer is hibernated and contains the memory data of the current system so that it can be quickly restored to the previous state during recovery. Since its size is equal to the memory capacity, it may take up a larger amount of hard drive space. hiber

Detailed explanation of the role of .ibd files in MySQL and related precautions Detailed explanation of the role of .ibd files in MySQL and related precautions Mar 15, 2024 am 08:00 AM

Detailed explanation of the role of .ibd files in MySQL and related precautions MySQL is a popular relational database management system, and the data in the database is stored in different files. Among them, the .ibd file is a data file in the InnoDB storage engine, used to store data and indexes in tables. This article will provide a detailed analysis of the role of the .ibd file in MySQL and provide relevant code examples to help readers better understand. 1. The role of .ibd files: storing data: .ibd files are InnoDB storage

What is the difference in the 'My Computer' path in Win11? Quick way to find it! What is the difference in the 'My Computer' path in Win11? Quick way to find it! Mar 29, 2024 pm 12:33 PM

What is the difference in the "My Computer" path in Win11? Quick way to find it! As the Windows system is constantly updated, the latest Windows 11 system also brings some new changes and functions. One of the common problems is that users cannot find the path to "My Computer" in Win11 system. This was usually a simple operation in previous Windows systems. This article will introduce how the paths of "My Computer" are different in Win11 system, and how to quickly find them. In Windows1

Analysis of new features of Win11: How to skip logging in to Microsoft account Analysis of new features of Win11: How to skip logging in to Microsoft account Mar 27, 2024 pm 05:24 PM

Analysis of new features of Win11: How to skip logging in to a Microsoft account. With the release of Windows 11, many users have found that it brings more convenience and new features. However, some users may not like having their system tied to a Microsoft account and wish to skip this step. This article will introduce some methods to help users skip logging in to a Microsoft account in Windows 11 and achieve a more private and autonomous experience. First, let’s understand why some users are reluctant to log in to their Microsoft account. On the one hand, some users worry that they

Analysis of the meaning and usage of midpoint in PHP Analysis of the meaning and usage of midpoint in PHP Mar 27, 2024 pm 08:57 PM

[Analysis of the meaning and usage of midpoint in PHP] In PHP, midpoint (.) is a commonly used operator used to connect two strings or properties or methods of objects. In this article, we’ll take a deep dive into the meaning and usage of midpoints in PHP, illustrating them with concrete code examples. 1. Connect string midpoint operator. The most common usage in PHP is to connect two strings. By placing . between two strings, you can splice them together to form a new string. $string1=&qu

See all articles