自己写的一个小小的php登陆模块 推荐
2011-06-27 19:28
387 查看
今天写了一个小功能——PHP登陆 出来使用,才刚学PHP不久,有错误的地方请大虾们指正指正:
left.php 登陆页面
userlogin.php 验证功能
login.php 注销功能
config.auth.php 数据库连接功能
就四个页面,left.php通过post提交信息给userlog.php处理,userlog.php调用config.auth.php连接数据库进行数据处理,然后把结果返回left.php,logout.php就只是注销session功能。没有加入cookie,还暂时不需要保存cookie!代码如下:
left.php
config.php
userlogin.php
logout.php
left.php 登陆页面
userlogin.php 验证功能
login.php 注销功能
config.auth.php 数据库连接功能
就四个页面,left.php通过post提交信息给userlog.php处理,userlog.php调用config.auth.php连接数据库进行数据处理,然后把结果返回left.php,logout.php就只是注销session功能。没有加入cookie,还暂时不需要保存cookie!代码如下:
left.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>登陆系统</title> </head> <body> <?php session_start(); if ($_SESSION[username]) { ?> <form id="form3" name="form3" method="post" action=""> <table width="150" border="1"> <tr> <td width="64">当前用户</td> <td width="70"><?php echo $_SESSION[username];?></td> </tr> <tr> <td colspan="2"><div align="center"><a href="logout.php">注销</a></div></td> </tr> </table> </form> <?php }else { ?> <form id="form1" name="form1" method="post" action="userlogin.php"> <table width="150" border="1"> <tr> <td width="64">用户</td> <td width="70"><label> <input name="username" type="text" id="textfield" size="10" /> </label></td> </tr> <tr> <td>密码</td> <td><label> <input name="password" type="password" id="textfield2" size="10" /> </label></td> </tr> <tr> <td colspan="2"> <div align="center"> <input type="submit" name="submit" id="button" value="提交" /> <input type="reset" name="reset" id="button2" value="重置" /> </div></td> </tr> </table> </form> <?php } ?> </body> </html>
config.php
<?php $dbhost="localhost"; $dbuser="root"; $dbpassword="123456"; $dbname="auth"; $conn=mysql_connect("$dbhost","$dbuser","$dbpassword") or die('不能连接服务器'.mysql_error()); mysql_select_db("$dbname",$conn) or die("数据库访问错误".mysql_errno()); mysql_query("set names gb2312"); ?>
userlogin.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>登陆系统</title> </head> <body> <?php session_start(); require("config.auth.php"); if ($_POST[submit]) { $sql="select * from userinfo where username = '$_POST[username]' and password = '$_POST[password]'"; $result=mysql_query($sql); $numrows=mysql_num_rows($result); if ($numrows == 1) { $row=mysql_fetch_assoc($result); $_SESSION[username]=$row[username]; //echo $_SESSION[username]; echo "<script>alert('登陆成功!');window.location.href='left.php';</script>"; }else { echo "<script>alert('登陆失败!');window.location.href='index.html';</script>"; } }else { echo "<script>alert('请通过正确途径登陆!');window.location.href='index.html';</script>"; } mysql_free_result($result); mysql_close($conn); ?> </body> </html>
logout.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>登陆系统</title> </head> <body> <?php session_start(); unset($_SESSION[username]); session_destroy(); echo "<script>alert('注销成功!');window.location.href='index.html';</script>"; ?> </body> </html>
相关文章推荐
- 自己动手写一个推荐系统
- 用PHP程序为自己网站打造一个搜索引擎
- C# 自己写了一个windows服务程序,运行时错误: 错误 1053: 服务没有及时响应启动或控制请求。(推荐)
- 推荐一个很强的PHP图片处理(含缩图)类
- php的一个登录的类 [推荐]
- php 自己写的一个数组分类合并array_merge(函数的剖析)
- 一个自己开发的简单,快速,方便,小巧的php web框架
- 自己动手写一个推荐系统
- 手把手教你编写一个简单的PHP模块形态的后门
- 推荐给大家一个php代码格式化在线工具
- 发一个自己原创的迷你博客的PHP源程序(支持QQ、MSN和飞信机器人和短息接口)
- 选择php给自己一个机会
- 群上出的一个算法题,上我的解,大家可以用自己会的语言实现一下哦,我用的php
- linux下php 加装mssql模块 推荐
- 自己制作一个node_modules的模块
- SugarCRM 一个页面控制两个模块(editview.php)
- 给大家推荐一个真正的免费空间,支持asp.net,PHP,多种数据库,空间容量无限
- 如何用AWS(亚马逊云服务器)搭建一个自己的blog (3) – 如何登陆到AWS建立的网络服务器
- 自己写了一个php检测文件编码的函数
- php实现登陆模块功能示例