分享自己的PHP项目编程
konv 2003-07-12 01:08:26 一直想把PHP跟hmtl分开,这样对以后的维护大型网站方便,总结一下以前写php的方法。
不知道大家是不是这样写的?或者有更好的结构,可不可以拿出来分享一下。
PHP的项目编程模式(sms):
#####################################
登陆界面
/sms/index.php
<html>
<head>
<title>sms login</title>
</head>
<body>
<form action="/sms/login/loginView.php" method="post">
<p>手机号码:<input type="text" name="handset">
<p>手机密码:<input type="password" name="password">
<p><input type="submit" value="登陆">
</form>
</body>
</html>
#################################
登陆检查
/sms/login/loginView.php
<?php
include_once "/includes/smsTemplate.php";/*模板文件*/
include_once "/sms/login.php";
$q=new login();
$q->doEXcute.php
head("标题");
?>
<p>登陆成功;
<?php
footer();
?>
#################################
登陆使用的Class
/sms/login/login.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] ."/sms/sms.php";
include_once $_SERVER['DOCUMENT_ROOT'] ."/db/Mysql.php";
class login extends sms
{
var $handset;
var $password;
function login(){
$this->handset=$_POST['handset'];
$this->password=$_POST['password'];
}
/**
* @desc 执行函数
*/
function doExcute(){
$this->checkHandset();
$this->checkHandsetPassword();
}
/**
* @desc 检查手机号码是否正确
*/
function checkHandset(){
$handsetModle="^13[0-9]{9}";
if(!ereg($handsetModel,$this->handset)) $this->showError("errHandsetModel");
}
/**
* @desc 检查手机号码
*/
function checkHandsetPassword(){
$sql="select * from smsUsers
where handset='$this->handset' and password='$this->password'"
$this->query($sql);
$nums=$this->getNums();
if(!$muns) $this->showError("errhandsetLogin");
}
/**
* @desc错误跳转
*/
function showError($msg){
head("location:/err/showError.php?errMsg=$msg");
exit;
}
}
#######################
连接数据库文件
/sms/sms.php
class sms extends mysql
{
function query($sql=""){}
function getNums(){}
}
#########################
/*网页模板文件*/
/includes/smsTemplate.php;
function head($title){}
function footer(){};
#############################
/err/showError.php /*错误显示*/
<html>
<script>
alert(<?php echo $errMsg ;?>);
history.back();
</script>
</html>