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

php用户登录代码

发布:smiling 来源: PHP粉丝网  添加日期:2014-01-15 10:45:26 浏览: 评论:0 

一款讲得非常详细的登录代码,对php入门者有很大的帮助,有需要的朋友可以免费查看,效果图如下:

 

index.php,代码如下:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> 
  5. <title>系统登录</title> 
  6. <link href="css.css" rel="stylesheet" type="text/css" /> 
  7. </head> 
  8. <body> 
  9. <div id="box"
  10.   <div id="denglu"
  11.   <div id="pic">&nbsp;系统后台登陆</div> 
  12.     <form action="check.php" method="post"
  13.       <p>用户名: 
  14.         <input type="text" name="name" id="name" /> 
  15.       <span class="must">*</span></p> 
  16.       <p>密&nbsp;&nbsp;码: 
  17.         <input name="password" type="password" id="password" /> 
  18.       <span class="must">*</span></p> 
  19.       <p>验证码: 
  20.         <input name="check" type="text" id="check" size="8" /> 
  21.         <img src="piccheck.php" /> <span class="must">*</span></p> 
  22.       <p class="form_button"
  23.         <input type="submit" name="sub" id="sub" value="登陆" /> 
  24.         <input type="reset" name="unsub" id="unsub" value="取消" /> 
  25.       </p> 
  26.     </form> 
  27.   </div> 
  28. </div> 
  29. </body> 
  30. </html> 

 

数据库连接connect.php,代码如下:

  1. <?php 
  2.  $connect=mysql_connect("localhost","root","")or die("服务器连接失败"); 
  3.  mysql_select_db("test",$connect)or die("没有建立相应的数据库"); 
  4. $sql="select * from admin"
  5. ?> 

 

图片验证码 piccheck.php,代码如下:

  1. <?php 
  2. /* 
  3.  * Created on 2011-8-10 
  4.  * 
  5.  * To change the template for this generated file go to 
  6.  * Window - Preferences - PHPeclipse - PHP - Code Templates 
  7.  */ 
  8.  session_start(); 
  9.  $code=rand(0,9).dechex(rand(10,15)).rand(0,9).dechex(rand(10,15)); 
  10.  $_SESSION[pic]=$code
  11.  $image=imagecreatetruecolor(50,18); 
  12.  $color=imagecolorallocate($image,0,0,0);//第一次使用调色板,会设为背景颜色 
  13.  $colortext=imagecolorallocate($image,rand(100,255),rand(100,255),rand(100,255)); 
  14.  imagestring($image,10,rand(1,15),rand(1,5),$code,$colortext); 
  15.  imagegif($image); 
  16. ?> 

 

css.css文件,代码如下:

  1. @charset "utf-8"
  2. /* CSS Document */ 
  3. body { 
  4.  background-color#9CF
  5.  text-alignleft
  6. #denglu { 
  7.  width400px
  8.  margin-top0px
  9.  margin-rightauto
  10.  margin-bottom0px
  11.  margin-leftauto
  12.  background-imageurl(images/login.gif); 
  13.  background-repeatno-repeat
  14.  height320px
  15.  text-indent6px
  16. #box #denglu form { 
  17.  positionrelative
  18.  top: 50px
  19.  left: 10px
  20.  width92%
  21. .must { 
  22.  color#F00
  23.  font-size12px
  24. #box #denglu #pic { 
  25.  background-imageurl(images/dot1.gif); 
  26.  background-repeatno-repeat
  27.  height20px
  28.  width100px
  29.  font-size12px
  30.  color#F00
  31.  text-alignleft
  32.  line-height18px
  33.  left: 10px
  34.  top: 30px
  35.  positionrelative

Tags: php 用户登录 代码

分享到: