https://github.com/xiao555/router-php
A PHP register/login Demo with router function
https://github.com/xiao555/router-php
php-demo php-router router
Last synced: about 2 months ago
JSON representation
A PHP register/login Demo with router function
- Host: GitHub
- URL: https://github.com/xiao555/router-php
- Owner: xiao555
- Created: 2017-01-19T06:36:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-16T14:05:23.000Z (over 9 years ago)
- Last Synced: 2025-03-06T00:17:08.980Z (over 1 year ago)
- Topics: php-demo, php-router, router
- Language: PHP
- Size: 593 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 带简单的Router功能的PHP注册登录Demo
### 环境
1. MacOS
2. XAMPP
### 配置数据库和安装依赖
1. 执行sql脚本 `init.php` 创建所需的数据库和表
2. 配置 `/Models/database.json` 填上root密码
3. 安装依赖 `composer install`
### 配置服务器通过域名访问
这个方法已经可以放弃了。。。直接被服务器访问就行,就不删了
1. 修改hosts
```bash
sudo nano /etc/hosts
```
在最后添加: `127.0.0.1 localtest # 你想设置的域名`
2. 开启虚拟主机
修改xampp配置,编辑`/Applications/XAMPP/xamppfiles/etc/httpd.conf`
搜索`httpd-vhosts.conf`,把这行前面的注释去掉,在最后加上这样一段:
```conf
#Options Indexes FollowSymLinks ExecCGI Includes #don't >permission see list
Options All
AllowOverride All
Order allow,deny
Allow from all
```
3. 配置虚拟主机
编辑`/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf`
```conf
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/php-login-register/"
ServerName localtest
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/"
ServerName localhost
```
### 运行
1. 普通方法
本地直接访问即可,例如: `127.0.0.1/php-login-register/`(注意最后一个`/`).
2. 配置虚拟主机
重启xampp,在本地服务器上,浏览器打开[localhost](localhost) 、 [localtest](localtest) 以及 [127.0.0.1](127.0.0.1) 看看效果。
另外,也可以找一个闲置的域名解析成127.0.0.1,这样访问域名就会解析到本地。
### 说明
前身是 [简单的PHP注册登录Demo](https://github.com/xiao555/PHP-register-login) 在此基础上进行改造。
首先,要实现路由功能,网站的入口只有一个,index.php
这就需要配置一下`.htaccess`伪静态,关于`.htaccess`的可以参考[.htaccess基本语法和应用](http://blog.sina.com.cn/s/blog_6e8b46e701014drc.html)
router逻辑是用的[phroute](https://github.com/mrjgreen/phroute).
目前逻辑都写在`index.php`里,模板放在`Views`目录下,封装了两个自定义函数`render`和 `redirect`,实现模板分离已经够用了。
密码采用hash加密,增强了安全性(==!).
不足:
1. `phroute` 还不是很熟悉,需要研究
2. `.htaccess`的配置需要学习一下
3. 还需要加个`/Public`存放静态资源