当前位置:首页 > 综合实例 > 列表

php登录代码

发布:smiling 来源: PHP粉丝网  添加日期:2013-12-16 16:50:28 浏览: 评论:0 

php登录代码 这是一款完整理的php登录代码实例哦,他从数据库到html以及php程序,整个过程都一步步写出来了,是一款非常不错的入门级登录php代码。

  1. session_start(); 
  2. /* get post */   
  3.  if (!function_exists("getpost")){function getpost(){if(count($_post)){foreach($_post as $key => $value){global ${$key};${$key}=$value;}}}} 
  4. /* get get */   
  5.  if (!function_exists("getget")){function getget(){if(count($_get)){foreach($_get as $key => $value){global ${$key};$$key=($value);}}}} 
  6. /* sql escape string */ 
  7. if (!function_exists("escapeit")){ 
  8. function escapeit($text){  
  9.  if (get_magic_quotes_gpc()) $text=strips教程lashes($text); 
  10.  if (!is_numeric($text)) $text=mysql教程_real_escape_string($text); 
  11.  return $text
  12. }} 
  13.   
  14. getpost(); //获取post过来的数据 
  15.  
  16. //login 
  17. $rs = $db->query("select * from `backend_user` where binary `login` = '".escapeit($login)."' and binary `password` = '".md5($password)."'"); 
  18. if (mysql_num_rows($rs) > 0) { 
  19.  $row = $db->fetch_array($rs); 
  20.  $_session["smartinfo_sysid"] = $row["user_id"]; 
  21.  $_session["smartinfo_syslogin"] = $row["login"]; 
  22.  $db->query("update `backend_user` set `last_logon` = '".date("y-m-d h:i:s")."' where `id` = '".$row["id"]."'"); 
  23.  header("location: index2.php"); 
  24. else { 
  25.  header("location: index.php?status=fail"); 
  26. //利用到的函数 
  27. ?> 

html代码

  1. <table width="100%" height="100%" cellpadding="0" cellspacing="0"><tr><td> 
  2.   <table width="350" align="center" cellpadding="0" cellspacing="0"> 
  3.       <tr> 
  4.         <td align="center" class="heading"><div style="font-size:12px;" align="left">control paneldiv>td> 
  5.       tr> 
  6.   table> 
  7.   <table width="350" align="center" cellpadding="0" cellspacing="0" class="tableborder"> 
  8.   <form action="login.php" method="post" name="login" id="login" onsubmit="return checkvalid(this);"> 
  9.      
  10.     <tr> 
  11.       <td align="center"><img src="images/logo.jpg" width="198" height="61">td> 
  12.       tr> 
  13.     <tr> 
  14.       <td class="c1" align="right" style="height:10px">td> 
  15.     tr> 
  16.     <tr><td><table width="85%" align="center" cellpadding="0" cellspacing="0"> 
  17.  <tr> 
  18.       <td style="font-size:12px"><b>login id:b>td> 
  19.       <td align="right"><input name="login" type="text" style="width:220px" >td> 
  20.     tr> 
  21.     <tr> 
  22.       <td style="font-size:12px"><b>password:b>td> 
  23.       <td align="right"><input name="password" type="password" style="width:220px" size="2" maxlength="15">td> 
  24.     tr> 
  25.     <tr> 
  26.   <td>td> 
  27.       <td align="right" valign="top"><input type="submit" name="submit" id="submit" value="login" class="button">td> 
  28.     tr> 
  29.  table>td>tr> 
  30.  <tr> 
  31.    <td class="c1" align="right" style="height:10px">td> 
  32.  tr> 
  33.   form> 
  34. table> 
  35. td>tr>table> 

数据库

  1. -- 
  2. -- 表的结构 `backend_user` 
  3. -- 
  4. create table if not exists `backend_user` ( 
  5.   `user_id` int(11) not null auto_increment, 
  6.   `group_id` int(11) not null default '0'
  7.   `login` varchar(255) not null default ''
  8.   `passwordvarchar(255) not null default ''
  9.   `last_logon` datetime not null default '0000-00-00 00:00:00'
  10.   primary key  (`user_id`) 
  11. ) engine=myisam  default charset=utf8 auto_increment=2 ; 
  12. -- 
  13. -- 导出表中的数据 `backend_user` 
  14. -- 
  15. insert into `backend_user` (`user_id`, `group_id`, `login`, `password`, `last_logon`) values 
  16. (1, 0, 'admin''e10adc3949ba59abbe56e057f20f883e''0000-00-00 00:00:00'); 

Tags: php 登录 代码

分享到: