1. 打开Apache配置文件 httpd.conf中查找Include conf/extra/httpd-vhosts.conf

2. 根据上面的路径,在Apache文件夹中找到httpd-vhosts.conf这个文件

3.打开文件,将截图部分复制一份粘贴在此文档最下方,并删除掉注释符号,将DocumentRoot后面的名字改成项目路径:
此项目路径在c盘:C:/phpStudy/PHPTutorial/WWW/company

4. 将servername改成自己网站的域名:

5.重启Apache
6.打开文件夹:C:\Windows\System32\drivers\etc中的hosts文件,加入这一句:127.0.0.1 www.yixing666.com

一般会建文件夹分别装前后台文件
例如 home、index等文件夹就可能是装前台的文件
admin就是装后台的文件

/*
index.php相当于一个入口
这就是项目入口
m moudel 模块
c controller 控制器
www.yixing666.com?m=home&c=news 进入b模块(文件夹home)中的c控制器名称(具体哪一个页面)
*/
//m是文件夹名,如果有(网址中能接收到这个值)就进入这个模块(文件夹),没有就进入前台模块(home文件夹)
$m = isset($_GET['m']) ? $_GET['m'] : 'home';
//c是文件名,如果有(网址中能接收到这个值)就进入这个控制器(文件),没有就给index(控制器名称,就是首页文件名index.php)
$c = isset($_GET['c']) ? $_GET['c'] : 'index';
$filename = $m.'/'.$c.'.php';//构造出网址: home/news.php
include_once($filename);//include 包含并运行指定文件,此时输入网址www.yixing666.com已经可以打开home文件夹里的index.php文件并显示出其中的内容了
现在只需要修改m、c的值,就可以进入建好的这些页面

<?php
/*
index.php相当于一个入口
这就是项目入口
m moudel 模块
c controller 控制器
www.yixing666.com?m=home&c=news 进入b模块(文件夹home)中的c控制器名称(具体哪一个页面)
*/
//m是文件夹名,如果有(网址中能接收到这个值)就进入这个模块(文件夹),没有就进入前台模块(home文件夹)
$m = isset($_GET['m']) ? $_GET['m'] : 'home';
//c是文件名,如果有(网址中能接收到这个值)就进入这个控制器(文件)
//没有就给index(控制器名称,就是首页文件名index.php)
$c = isset($_GET['c']) ? $_GET['c'] : 'index';
$filename = $m.'/'.$c.'.php';//构造出网址: home/news.php
//file_exists()函数检查文件或目录是否存在。
//假如用户输错m或c的话:
//进行判断,如果输入正确,就显示正确页面,输入不正确,就输出页面不存在
if(file_exists($filename)){
include_once($filename);
}else{
die("($filename)不存在");
}
//include_once($filename);include 包含并运行指定文件,此时输入网址www.yixing666.com已经可以打开home文件夹里的index.php文件并显示出其中的内容了
?>
在入口文件(首页)用这个函数创建一个常量作为key,在其他页面接收检测这个常量
define('TICKET', 1);
检测 是否通过入口访问:
defined('TICKET') or die('Denny');

index.php相当于一个入口
这就是项目入口
www.yixing666.com?m=home&c=news 进入b模块(文件夹home)中的c控制器名称(具体哪一个页面)
通过建立:
入口文件建立凭证 => 公共文件验证凭证 => 其他页面引入公共文件
的架子实现验证,这就是单入口模式
单入口模式特点:
安全(不用这样入口的话,在浏览器中随便打一个文件夹可能就可以访问了)
<?php
/*
index.php相当于一个入口
这就是项目入口
m moudel 模块
c controller 控制器
www.yixing666.com?m=home&c=news 进入b模块(文件夹home)中的c控制器名称(具体哪一个页面)
通过建立:
入口文件建立凭证 => 公共文件验证凭证 => 其他页面引入公共文件
的架子实现验证,这就是单入口模式
单入口模式特点:
安全(不用这样入口的话,在浏览器中随便打一个文件夹可能就可以访问了)
*/
//m是文件夹名,如果有(网址中能接收到这个值)就进入这个模块(文件夹),没有就进入前台模块(home文件夹)
$m = isset($_GET['m']) ? $_GET['m'] : 'home';
//c是文件名,如果有(网址中能接收到这个值)就进入这个控制器(文件)
//没有就给index(控制器名称,就是首页文件名index.php)
$c = isset($_GET['c']) ? $_GET['c'] : 'index';
//要产生一个凭证用户通过这个凭证可以去往其他页面
//然后其他页面通过检测这个凭证确认是否让用户访问
//产生一个凭证 使用常量(定义后不能被更改)
//常量前面不能有 $ 符号
//通常全部大写(用于区分)
//define() 定义一个常量。
//define('name', value);
//其他所有页面都要加检测语句 defined('TICKET') or die('Denny');
define('TICKET', 1);
$filename = $m.'/'.$c.'.php';//构造出网址: home/news.php
//file_exists()函数检查文件或目录是否存在。
//假如用户输错m或c的话:
//进行判断,如果输入正确,就显示正确页面,输入不正确,跳转到404页面
if(file_exists($filename)){
include_once($filename);
}else{
header("location: 404.html");
}
//include_once($filename);include 包含并运行指定文件,此时输入网址www.yixing666.com
//已经可以打开home文件夹里的index.php文件并显示出其中的内容了
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>404</title>
</head>
<body>
<h1 align="center">404</h1>
<p align="center">页面不存在</p>
</body>
</html>
<?php
require_once('init.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>前台首页</h1>
</body>
</html>
<?php
require_once('init.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>新闻列表</h1>
</body>
</html>
用于验证入口文件传过来的参数
<?php
/*
init.php 初始化文件 公共文件
*/
//检测是否通过入口访问
//define 创建一个常量 defined 检测常量 ,就一个 d 的差别
//这行代码作用是 检测到这个常量就继续,否则退出
//退出可以是输出一行提示消息,也可以跳转到某个页面
defined('TICKET') or die('Denny');
?>
<?php
require_once('init.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>后台首页</h1>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>编辑新闻</h1>
</body>
</html>
用于验证入口文件传过来的参数
<?php
defined('TICKET') or die('Denny');
?>
网友评论