(新)PHP 用戶登錄+驗證碼的

下面我作的是PHP的登錄功能:有驗證碼功能的:php

設計界面:mysql

 

登錄功能網頁:sql

<?php
session_start();
if(!empty($_POST['aaa'])){
  if(strtoupper($_POST["yzm"])!=$_SESSION["vcode"])
 {
  die("<script>alert('驗證碼輸入錯誤!');window.navigate('SR_1.php');</script>");
 }      //驗證碼部分:
$username = $_REQUEST['username'];   //把會話的值存入到變量$username中
$_SESSION['username']=$username;
$password = $_REQUEST['password'];
mysql_connect('localhost','root','123456');
mysql_select_db('yy');
$sql = "select * from users where username=$username and password=$password";
$result=mysql_query($sql);
if(mysql_num_rows($result)>=1){
      echo "<script>alert('登錄成功,跳轉留言本ing.');location='SR_7.php'</script>";
}else{
  echo "<script>alert('登錄失敗:密碼錯誤或用戶不存在');</script>";
  }  
  }
mysql_close();?>數組


<h1><img src="p_w_picpaths/1.jpg" width="200" height="200" /></h1><br />
<form method="post" name="aa">
<h1><font color="#FF0000">用戶登錄</font><font size="-1" color="#FF9900"></font></h1>
用戶名:<input type="text" name="username" id="username" /><br />
密&nbsp;&nbsp;&nbsp;&nbsp;碼:
<input type="password" name="password" />
<br />
<br />
驗證:<input name="yzm" type="text" style="width:32px; height:16px; background-color:#292929; border:solid 1px #7dbad7; font-size:12px; color:#6cd0ff" maxlength="4">
<img onClick="this.src=this.src+'?a=Math.random()'" src="SR_1-1.php" alt="看不清?請點擊!">      //驗證碼的那張圖片
<br>
<input type="submit" name="aaa" value="登錄" />
<a href="SR_6.php">修改密碼" </a>
</form>session

 

驗證碼的網頁://這部分是能夠實現的!但我仍是記不住,呵呵!dom

<?php
session_start();
$string="ABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";//存儲驗證碼內容
//1 產生隨機數,存入str數組,vcode變量
$_SESSION["vcode"]="";
for($i=0;$i<4;$i++)
{
 $str[$i]=$string[rand(0,33)];
 //2 將輸入存入session中
 $_SESSION["vcode"].=$str[$i];
}ide

//3 建立圖像
$w=80;//圖像的寬高
$h=26;
$im=p_w_picpathcreatetruecolor($w,$h);//建立圖像
$bg1=p_w_picpathcolorallocate($im,255,255,255);//白色
$bg2=p_w_picpathcolorallocate($im,0,0,0);//黑色
p_w_picpathfilledrectangle($im,0,0,$w,$h,$bg1);//繪製一個矩形
p_w_picpathrectangle($im,0,0,$w-1,$h-1,$bg2);//繪製邊框
//生成雪花背景,干擾
for($i=1;$i<=200;$i++)
{
 $x=rand(1,$w-9);
 $y=rand(1,$h-9);
 $color=p_w_picpathcolorallocate($im,rand(150,255),rand(150,255),rand(150,255));
 p_w_picpathstring($im,1,$x,$y,"*",$color);
}
//4 將數據寫入圖像
for($i=0;$i<4;$i++)
{
 $x=13+$i*($w-15)/4;//分配四個數的x位置
 $y=rand(3,$h/3);//分配Y軸4個數位置
 $color=p_w_picpathcolorallocate($im,rand(0,150),rand(0,150),rand(0,150));
 p_w_picpathstring($im,5,$x,$y,$str[$i],$color);//將數據寫入圖像
}
header("Content-type:p_w_picpath/jpeg");
p_w_picpathjpeg($im);
?>post

相關文章
相關標籤/搜索