PHP如何用Smarty写静态登录

这里我给大家提供的只有代码不分,需要的文件需要自行下载,libs文件不提供。。。

首先是数据库:smarty.sql

/*
Navicat MySQL Data Transfer

Source Server         : qq
Source Server Version : 50133
Source Host           : localhost:3306
Source Database       : smarty

Target Server Type    : MYSQL
Target Server Version : 50133
File Encoding         : 65001

Date: 2011-11-14 16:44:23
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `student`
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `studentNum` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
  `password` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=gbk;

-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES ('12', '20044021', '123456');
INSERT INTO `student` VALUES ('13', '20044149', '000000');
INSERT INTO `student` VALUES ('14', '20044173', '000000');
INSERT INTO `student` VALUES ('16', '20044152', '000000');
INSERT INTO `student` VALUES ('17', '20044003', '000000');
INSERT INTO `student` VALUES ('18', '20044023', '000000');

接下来是php文件:

index.php

<?php  
   require("./libs/Smarty.class.php");

   $tpl = new Smarty(); //建立smarty实例对象$smarty
   $tpl->template_dir = "./templates/";//设置模板目录
   $tpl->compile_dir  = "./Stemplates_c/"; //设置编译目录
   $tpl->config_dir   = "./configs/";

   $tpl->left_delimiter = "<{"; 
   $tpl->right_delimiter = "}>";

   $tpl->display("index.tpl");

?>

 

check.php

<?php  
   $studentNum = @$_POST['studentNum'];
   $password = @$_POST['password'];

   $conn = mysql_connect("localhost","root","");
   mysql_select_db("smarty",$conn);
   mysql_query("set names 'utf8'");
   $result = mysql_query("select password from student where studentNum = '$studentNum' and password = '$password'");
   while($row = mysql_fetch_row($result))
   {
    $array[]=$row;
   }
   mysql_free_result($result);
   if(count(@$array))
   {
     echo "登录成功!!!";
   }
   else
   {
  echo "用户名或密码不正确!";
   }
?>

最后是模板文件:

index.tpl

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> Smarty用户登录</TITLE>
 </HEAD>

 <BODY>
    <form id="form1" name="form1" method='post' action="check.php">
 
    <table align="center" >
    <tr>
        <td align="right">学号:</td>
        <td><input name="studentNum" type="text"></td>
    </tr>
    <tr>
        <td align="right">密码:</td>
        <td><input name="password" type="password"></td>
    </tr>
    <tr>
       <td align="right"><input type="submit" value="提交"></td>

    </tr>
     </table>
 </form>
 </BODY>
</HTML>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值