Skip to content

Commit f69eda5

Browse files
committed
add shop
1 parent 7337408 commit f69eda5

File tree

11 files changed

+322
-0
lines changed

11 files changed

+322
-0
lines changed

shop/.DS_Store

6 KB
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
class AdminController{
3+
4+
/**
5+
* 展示登陆页面
6+
* @return [type] [description]
7+
*/
8+
public function indexAction(){
9+
require './app/view/back/login.html';
10+
}
11+
12+
public function signinAction(){
13+
//调用模型完成数据库操作
14+
//利用用户名 和 密码 验证用户身份
15+
$model_admin = new AdminModel;
16+
if ($model_admin->checkByLogin($_POST['username'],$_POST['password'])) {
17+
echo '合法用户';
18+
}else{
19+
echo '非法用户';
20+
}
21+
}
22+
}

shop/app/model/AdminModel.class.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
//require ('./framework/Model.class.php');
3+
/**
4+
* demo_admin表模型
5+
*/
6+
class AdminModel extends Model{
7+
/**
8+
* 利用登陆用户名 密码 进行登录验证
9+
* @param [type] $admin_name 用户名
10+
* @param [type] $admin_pass 用户密码
11+
* @return [type] [description]
12+
*/
13+
public function checkByLogin($admin_name,$admin_pass){
14+
$sql = "select * from demo_admin where admin_name='$admin_name' and admin_pass=md5('$admin_pass')";
15+
$row = $this->db->fetchRow($sql);
16+
//var_dump($row);
17+
return (bool)$row;
18+
}
19+
}

shop/app/view/back/login.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<title>控制台_登陆</title>
6+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7+
<link href="styles/general.css" rel="stylesheet" type="text/css" />
8+
<link href="styles/main.css" rel="stylesheet" type="text/css" />
9+
10+
<style type="text/css">
11+
body {
12+
color: white;
13+
}
14+
</style>
15+
16+
<script language="JavaScript">
17+
18+
if (window.parent != window)
19+
{
20+
window.top.location.href = location.href;
21+
}
22+
23+
//-->
24+
</script>
25+
</head>
26+
<body style="background: #278296">
27+
<form method="post" action="index.php?p=back&c=Admin&a=signin" name='theForm' onsubmit="return validate()">
28+
<table cellspacing="0" cellpadding="0" style="margin-top: 100px" align="center">
29+
<tr>
30+
<td><img src="./images/20111009083544484.jpg" width="178" height="256" border="0" alt="" /></td>
31+
<td style="padding-left: 50px">
32+
<table>
33+
<tr>
34+
<td>管理员姓名:</td>
35+
<td><input type="text" name="username" /></td>
36+
</tr>
37+
<tr>
38+
<td>管理员密码:</td>
39+
<td><input type="password" name="password" /></td>
40+
</tr>
41+
<tr>
42+
<td>验证码:</td>
43+
<td><input type="text" name="captcha" class="capital" /></td>
44+
</tr>
45+
<tr>
46+
<td colspan="2" align="right"><img src="index.php?act=captcha&103316096" width="145" height="20" alt="CAPTCHA" border="1" onclick= this.src="index.php?act=captcha&"+Math.random() style="cursor: pointer;" title="看不清?点击更换另一个验证码。" />
47+
</td>
48+
</tr>
49+
<tr><td colspan="2"><input type="checkbox" value="1" name="remember" id="remember" /><label for="remember">请保存我这次的登录信息。</label></td></tr>
50+
<tr><td>&nbsp;</td><td><input type="submit" value="进入管理中心" class="button" /></td></tr>
51+
<tr>
52+
<td colspan="2" align="right">&raquo; <a href="../" style="color:white">返回首页</a> &raquo; <a href="get_password.php?act=forget_pwd" style="color:white">您忘记了密码吗?</a></td>
53+
</tr>
54+
</table>
55+
</td>
56+
</tr>
57+
</table>
58+
<input type="hidden" name="act" value="signin" />
59+
</form>
60+
</body>

shop/framework/.DS_Store

6 KB
Binary file not shown.

shop/framework/Model.class.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
//require './framework/MySQLDB.class.php';
3+
class Model{
4+
5+
protected $db;
6+
7+
public function __construct(){
8+
$this->initLink();
9+
}
10+
11+
protected function initLink(){
12+
$options = array(
13+
'host' =>'127.0.0.1',
14+
'port' => '3306',
15+
'user' => 'root',
16+
'pass' =>'root',
17+
'charset' => 'utf8',
18+
'dbname' => 'demo_shop'
19+
);
20+
21+
$this->db = MySQLDB::getInstance($options);
22+
}
23+
}
24+

shop/framework/MySQLDB.class.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
class MySQLDB{
3+
//初始化属性
4+
private $host;
5+
private $port;
6+
private $user;
7+
private $pass;
8+
private $charset;
9+
private $dbname;
10+
11+
//运行时生成属性
12+
private $link;
13+
private $last_sql;
14+
15+
//当前的实例对象
16+
private static $instance;
17+
18+
/**
19+
* 初始化连接参数
20+
* @param array $params [description]
21+
*/
22+
private function __construct($params = array()){
23+
$this->host = isset($params['host'])?$params['host']:'127.0.0.1';
24+
$this->port = isset($params['port'])?$params['port']:'3306';
25+
$this->user = isset($params['user'])?$params['user']:'root';
26+
$this->pass = isset($params['pass'])?$params['pass']:'root';
27+
$this->charset = isset($params['charset'])?$params['charset']:'utf8';
28+
$this->dbname = isset($params['dbname'])?$params['dbname']:'match';
29+
30+
$this->conn();
31+
$this->setCharset();
32+
$this->selectDB();
33+
}
34+
35+
/**
36+
* 单例 私有化clone
37+
* @return [type] [description]
38+
*/
39+
private function __clone(){
40+
41+
}
42+
43+
/**
44+
* 获得单例对象
45+
* @param [type] $params [description]
46+
* @return [type] [description]
47+
*/
48+
public static function getInstance($params){
49+
if (!(self::$instance instanceof self)) {
50+
self::$instance = new self($params);
51+
}
52+
return self::$instance;
53+
}
54+
55+
56+
/**
57+
* 数据库连接
58+
*/
59+
private function conn(){
60+
if(!$link = mysql_connect("$this->host:$this->port",$this->user,$this->pass)){
61+
echo '连接失败<br/>';
62+
echo mysql_errno().'<br/>';
63+
echo mysql_error();
64+
die();
65+
}
66+
$this->link = $link;
67+
}
68+
69+
/**
70+
* 设置字符集
71+
*/
72+
private function setCharset(){
73+
return $this->query("set names $this->charset");
74+
}
75+
76+
/**
77+
* 设置连接数据库
78+
*/
79+
private function selectDB(){
80+
if ($this->dbname === '') {
81+
return;
82+
}
83+
return $this->query("use `$this->dbname`");
84+
}
85+
86+
/**
87+
* 执行SQL的方法
88+
* @param [type] $sql 待执行的SQL
89+
* @return [type] 执行后结果
90+
*/
91+
public function query($sql){
92+
$this->sql = $sql;
93+
if (!$result = mysql_query($sql)) {
94+
echo '操作失败!<br>';
95+
echo '出错的sql是:'.$this->sql;
96+
echo mysql_errno().'<br>';
97+
echo mysql_error();
98+
die();
99+
}
100+
return $result;
101+
}
102+
/**
103+
* 获取执行SQL所有数据
104+
* @param [type] $sql 待执行
105+
* @return [type] 执行返回结果
106+
*/
107+
public function fetchAll($sql){
108+
if ($result = $this->query($sql)) {
109+
$rows = array();
110+
while ($row = mysql_fetch_assoc($result)) {
111+
$rows[ ] = $row;
112+
}
113+
mysql_free_result($result);
114+
return $rows;
115+
}else{
116+
return false;
117+
}
118+
}
119+
120+
/**
121+
* 取出查询结果中第一行数据
122+
* @param [type] $sql 待执行SQL
123+
* @return [type] 返回数据
124+
*/
125+
public function fetchRow($sql){
126+
if ($result = $this->query($sql)) {
127+
$row = mysql_fetch_assoc($result);
128+
mysql_free_result($result);
129+
return $row;
130+
}else{
131+
return false;
132+
}
133+
}
134+
135+
/**
136+
* 取出查询结果中第一行第一列数据
137+
* @param [type] $sql 待执行的
138+
* @return [type] 返回数据
139+
*/
140+
public function fetchColoum($sql){
141+
if ($result = $this->query($sql)) {
142+
$row = mysql_fetch_row($result);
143+
mysql_free_result($result);
144+
return $row[0];
145+
}else{
146+
return false;
147+
}
148+
}
149+
150+
}
151+

shop/images/.DS_Store

6 KB
Binary file not shown.

shop/images/20111009083544484.jpg

82.9 KB
Loading

shop/index.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
//require './app/controller/back/AdminController.class.php';
4+
//require './app/model/AdminModel.class.php';
5+
6+
//确定当前的平台
7+
$p = isset($_GET['p'])?$_GET['p']:'back';
8+
define('PLATFORM',$p);
9+
10+
define('DS',DIRECTORY_SEPARATOR); //j简化目录分隔符 linux:/ windows: / 或 \
11+
define('ROOT_DIR',dirname(__FILE__).DS); //更目录 dirname() 获取参数得父目录
12+
define('APP_DIR',ROOT_DIR.'app'.DS); //应用程序目录
13+
define('CONT_DIR',APP_DIR.'controller'.DS); //控制器目录
14+
define('CURR_CONT_DIR',CONT_DIR.PLATFORM.DS); //当前控制器
15+
define('MODEL_DIR',APP_DIR.'model'.DS); //模型路径
16+
define('FRAME_DIR', ROOT_DIR.'framework'.DS); //框架路径
17+
18+
$c = isset($_GET['c'])?$_GET['c']:'Admin';
19+
$controll_name = $c.'Controller';
20+
21+
$a = isset($_GET['a'])?$_GET['a']:'index';
22+
$action_name = $a.'Action';
23+
24+
$controller = new $controll_name;
25+
$controller->$action_name();
26+
27+
28+
function __autoload($class_name){
29+
//两个特例
30+
$map = array(
31+
'MySQLDB' => FRAME_DIR.'MySQLDB.class.php',
32+
'Model' => FRAME_DIR.'Model.class.php'
33+
);
34+
//将所有的特例做成一个类与类名的映射
35+
//判断当前所需加载的类是否属于特例
36+
if (isset($map[$class_name])) {
37+
require $map[$class_name];
38+
}elseif (substr($class_name, -10) == 'Controller') {
39+
require CURR_CONT_DIR.$class_name.'.class.php';
40+
}elseif (substr($class_name,-5) == 'Model') {
41+
require MODEL_DIR.$class_name.'.class.php';
42+
}
43+
}

0 commit comments

Comments
 (0)